我的问题是
当前上下文不存在“Affiche()”。
类 OPPSVotesStatistiques
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using System.Configuration;
namespace Components.Jobs
{
class OPPSVotesStatistiques : SPJobDefinition
{
private Pmail p;
public OPPSVotesStatistiques()
: base()
{
}
public OPPSVotesStatistiques(string jobName, SPWebApplication webApplication)
: base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
{
this.Title = "ListLogger";
}
public override void Execute(Guid contentDbId)
{
Pmail p = new Pmail();
InsretListAvis addAvis = new InsretListAvis();
List<AttributMail> listMail = Pmail.Affiche();
foreach (AttributMail m in listMail)
{
info = addAvis.Insert(m.Projet, m.Phase, m);
}}}
class Pmail
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Autodiscover;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.Text.RegularExpressions;
namespace Components.MailVote
{
class Pmail
{
public Pmail()
{
}
public static List<AttributMail> Affiche()
{
List<AttributMail> lmail = new List<AttributMail>();
try
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//service.Credentials = new NetworkCredential( "{Active Directory ID}", "{Password}", "{Domain Name}" );
service.Credentials = new WebCredentials("mail@site.com", "pass");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("mail@site.com", RedirectionUrlValidationCallback);
Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
//The search filter to get unread email
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView view = new ItemView(50);
view.PropertySet = itempropertyset;
//Fire the query for the unread items
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, sf, view);
foreach (Item item in findResults.Items)
{
AttributMail m = new AttributMail();
item.Load(itempropertyset);
m.From = (item as EmailMessage).Sender.Name;
m.Sujet = item.Subject;
m.Txt = item.Body;
m.Date = item.DateTimeReceived.TimeOfDay.ToString();
m.Cc = item.DisplayCc;
lmail.Add(m);
} }
catch(Exception ex){
}
return lmail;}}}
阅读邮件并将数据插入 SPlist 是一项计时器工作。