使用EWS检索电子邮件,只需要正文中的文本

时间:2018-09-11 09:03:00

标签: c# asp.net service exchangewebservices

我能够检索所有电子邮件并将其记录下来,但似乎无法将正文变成纯文本。我尝试在这里查看其他示例,但似乎无法理解问题。下面是到目前为止的代码:

//retrieve emails in blocks of 50
int offset = 1;
int pageSize = 50;
bool moreEmails = true;

ItemView view = new ItemView(pageSize, offset, OffsetBasePoint.Beginning);
view.PropertySet = PropertySet.IdOnly;

while (moreEmails)
{
    findResults = service.FindItems(WellKnownFolderName.Inbox, view);

    foreach (var item in findResults.Items)
    {
         emails.Add((EmailMessage)item);
    }

    moreEmails = findResults.MoreAvailable;

    if (moreEmails)
    {
        view.Offset += pageSize;
    }
}

PropertySet properties = new 
PropertySet (BasePropertySet.FirstClassProperties);
service.LoadPropertiesForItems(emails, properties);
properties.RequestedBodyType = BodyType.Text;

我要在一个单独的函数中初始化变量:

private static void CheckRules()
{
    try
    {
        foreach (var EmailParam in emails)
        {
            FromEmail = EmailParam.From.Address.ToString();
            EmailDate = EmailParam.DateTimeReceived.ToString("yyyy-MM-dd hh:mm:ss");
            EmailSubject = EmailParam.Subject.ToString();
            EmailBody = EmailParam.Body.Text.ToString();
            etc...

同样,我只希望正文纯文本。预先感谢您的帮助!

0 个答案:

没有答案