简体   繁体   English

发送 Email 通过 EWS 标记为高重要性 API

[英]Send Email Marked High Importance via EWS API

Attempting to send an email marked as high importance via EWS API. Getting multiple compile errors and or issues stating missing assembly.正在尝试通过 EWS API 发送标记为高重要性的 email。出现多个编译错误和/或问题,指出缺少程序集。 Any help would be appreciated.任何帮助,将不胜感激。 Using the following namespaces:使用以下命名空间:

  • System系统
  • System.Drawing系统图
  • System.Data系统数据
  • Microsoft.Exchange.WebServices.Data Microsoft.Exchange.WebServices.Data
  • System.Collections.Generic System.Collections.Generic
  • System.Web系统.Web
  • System.Text系统文本
  • System.IO系统.IO
  • System.Linq系统.Linq

I've referenced all the MS Docs on the EWS API and aware that the importance is an enum but unsure of the class to use to set the argument;我已经参考了 EWS API 上的所有 MS 文档,并意识到重要性是一个枚举,但不确定 class 用于设置参数;

I've tried multiple bits of syntax eg email.Importance = 2 but getting enum conversion error.我尝试了多种语法,例如 email.Importance = 2 但出现枚举转换错误。

Current code is as follows:当前代码如下:

Success = true;
ErrorMessage = "";
try {
if (To == "" && CC == "" && BCC == "") {
    throw new Exception("Recipients was not provided");
}
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
string serviceUrl = "https://mail.mydomain.com/ews/exchange.asmx";
service.Url = new Uri(serviceUrl);

EmailMessage email = new EmailMessage(service);
email.Subject = Subject;
if (isHTML) {
    email.Body = new MessageBody(BodyType.HTML, Message);
} else {
    email.Body = new MessageBody(BodyType.Text, Message);
}
if (isHighImportance) {
    email.Importance = new ImportantChoiceType(HIGH);
} else {
    email.Importance = new ImportantChoiceType(NORMAL);
}   
char[] splitComma =  new char[]{','};
char[] splitAsterisk =  new char[]{'*'};
char[] splitSemicolon =  new char[]{';'};
char[] splitAny =  new char[]{',',';'};

//To
foreach (String r in To.Split(splitAny, StringSplitOptions.RemoveEmptyEntries))
{
    email.ToRecipients.Add(r.Trim());
}
//CC
foreach (String r in CC.Split(splitAny, StringSplitOptions.RemoveEmptyEntries)) 
{
    email.CcRecipients.Add(r.Trim());
}
//BCC
foreach (String r in BCC.Split(splitAny, StringSplitOptions.RemoveEmptyEntries)) 
{
    email.BccRecipients.Add(r.Trim());
}

//SaveDraft
email.Save(SearchFolderByName(service,"Drafts",mailbox));

// Add attachments
foreach (String att in Attachments.Split(splitSemicolon, StringSplitOptions.RemoveEmptyEntries)) 
{
    if (att.Contains(new string(splitAsterisk))) {
        String[] attArray = att.Split(splitAsterisk, StringSplitOptions.RemoveEmptyEntries);
        FileAttachment fileatt = email.Attachments.AddFileAttachment(attArray[0]);
        fileatt.IsInline = true;
        fileatt.ContentId = attArray[1];
    } else {
        email.Attachments.AddFileAttachment(att);
    }
}

//Send
if (SaveSent) 
{
    email.SendAndSaveCopy(SearchFolderByName(service,"SentItems",mailbox));
} else {
    email.Send();
}
}
catch (Exception e) 
{
Success = false;
ErrorMessage = e.ToString();
}

Importance property in EmailMessage class is Enum so you have to use importance enum. EmailMessage class 中的Importance属性是Enum ,因此您必须使用重要性枚举。

email.Importance = Importance.High // Or Importance.Low or Importance.Normal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM