【问题标题】:C# Outlook API subject encoding in Sent Items folder已发送邮件文件夹中的 C# Outlook API 主题编码
【发布时间】:2016-07-06 16:14:54
【问题描述】:

我正在使用来自 Microsoft Outlook API 的 sendmail 调用,可以找到 here.

我需要发送允许在主题中包含特殊字符(例如 é、à、ç 或 ñ)的邮件。

我找到了this post 关于如何对主题进行编码的信息,并且效果很好。这里的问题是,在已发送邮件文件夹中,主题与整个编码一起显示,就像微软没有解决它一样。

Image can be found here.(还不能发布图片)

这是一个已知问题还是有任何解决方法?找不到任何相关信息。

代码:

MicrosoftMessage.RootObject msMessage = new MicrosoftMessage.RootObject();
MicrosoftMessage.Message msg = new MicrosoftMessage.Message();

msg.Subject = "=?UTF-8?B?" + Convert.ToBase64String(Encoding.UTF8.GetBytes(subject)) + "?=";
msg.Body.ContentType = "HTML";
msg.Body.Content = body;

msMessage.Message = msg;

string mail;
using (MemoryStream memoryStream = new MemoryStream())
using (StreamReader reader = new StreamReader(memoryStream))
{
     DataContractJsonSerializer serializer = new DataContractJsonSerializer(msMessage.GetType());
     serializer.WriteObject(memoryStream, msMessage);
     memoryStream.Seek(0, SeekOrigin.Begin);
     mail = reader.ReadToEnd();
}

try
{
    WebClient wc = new WebClient();
    wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
    wc.Headers[HttpRequestHeader.Authorization] = "Bearer " + msInfo.AccessToken;
    wc.Headers[HttpRequestHeader.Accept] = "text/*, application/xml, application/json; odata.metadata=none";
    wc.UploadString("https://outlook.office.com/api/v2.0/me/sendmail", mail);
    return true;
}
catch (Exception ex)
{
    Log.Error("An error occurred while sending the mail.", ex);
    return false;
}

【问题讨论】:

    标签: c# email character-encoding outlook


    【解决方案1】:

    以防万一有人遇到同样的问题,解决方案正在添加

      wc.Encoding = System.Text.Encoding.UTF8;
    

    在尝试中并按原样发送主题,不使用 base 64 编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多