【问题标题】:Convert Outlook.MailItem body and attachment to UTF8 or stream将 Outlook.MailItem 正文和附件转换为 UTF8 或流
【发布时间】:2019-12-21 18:00:45
【问题描述】:

我必须以 UTF-8 或 streambyte 格式发布邮件内容的邮件正文和附件,并保留所有电子邮件正文格式。 进行此要求的最佳方法是什么。 谢谢

【问题讨论】:

  • 您有什么问题?编码从 Outlook 返回的 UTF-16 数据?将 Outlook 邮件转换为 txt / html / MIME 格式?还是别的什么?
  • 将 MailItem.body 或 MailItem.HTMLBody 用于任何字符串值时,不会保留邮件正文的格式。我的要求是获取 mailitem 正文,然后使用 REST api 发布内容。
  • 究竟是什么没有被保留?格式化?还是Unicode字符?没保存在哪里?如果您要发送 HTML 正文,它究竟是在哪里损坏的?你需要比这更具体。

标签: outlook-addin mailitem


【解决方案1】:

您可以使用 MailItem 类的 HTMLBody 属性,该属性返回或设置表示指定项目的 HTML 正文的字符串。

Sub CreateHTMLMail()  
 'Creates a new email item and modifies its properties.  
 Dim objMail As Outlook.MailItem  
 'Create email item  
 Set objMail = Application.CreateItem(olMailItem)  
 With objMail  
 'Set body format to HTML  
 .BodyFormat = olFormatHTML  
 .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>"  
 .Display  
 End With  
End Sub

要获取实际字节,您可以使用Encoding.UTF8.GetBytes 方法。

对于网络插件,您可以使用以下代码:

Office.context.mailbox.item.body.getAsync(
  "html",
  { asyncContext: "This is passed to the callback" },
  function callback(result) {
    // Do something with the result.
  });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多