I'm using the sendmail call from Microsoft Outlook API which can be found here.
I need to send mails allowing special characters in the subject such as é, à, ç or ñ.
I found this post about how to encode the subject and it worked well. The issue here is that in the Sent Items folder the subject is shown with the whole codification, it's like Microsoft doesn't resolve it.
Image can be found here. (Can't post images yet)
Is it a known issue or is there any workaround? Haven't been able to find any information about this.
The code:
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;
}