【发布时间】:2019-07-08 18:05:17
【问题描述】:
通过Attachments.Add() 将新的System.Net.Mail.Attachment 添加到Outlook.MailItem.Attachments 会导致System.ArgumentException: 'Sorry, something went wrong. You may want to try again.'
尝试将 Base64 编码的 JPEG 图像作为附件添加到 Outlook 中的邮件项目。我将编码图像存储为变量,将其转换为内存流,然后转换为附件。
public void CreateMessageWithAttachment() {
Outlook.MailItem mailIttem = thisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
string base64Attachment = "/...base64 gibberish";
MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64Attachment));
ContentType ct = new ContentType(MediaTypeNames.Image.Jpeg);
Attachment attachment = new Attachment(ms, ct);
attachment.ContentDisposition.FileName = "look_at_dis.jpg";
mailIttem.Subject = "Test e-mail message with attachment";
mailIttem.To = "friend@company.com";
mailIttem.Body = "This message has been generated programmatically";
mailIttem.Attachments.Add(attachment); // This raises "Sorry..." expression
mailIttem.Display(true);
}
引发System.ArgumentException: 'Sorry, something went wrong. You may want to try again.',它什么也没告诉我:-/
【问题讨论】:
标签: c# .net outlook-addin