使用RDCOMClient设置内容类型UTF-8

时间:2016-09-14 13:03:09

标签: r email utf-8 outlook rdcomclient

我无法在UTF-8中收到我的电子邮件正文。我的降价报告没问题,从RStudio运行时脚本工作 - 即正文文本为UTF-8。我的问题是,当我从命令行运行脚本时,我的电子邮件使用windows-1252编码,我并不是真的想要。

如何设置我的代码以指定我的电子邮件标头以使内容类型为UTF-8? InternetCodepage至少无法正常工作

以下R代码:

## Bodytext
bodyMail <- paste(__My UTF-8 message goes here__, sep  = "")

# init com api
OutApp <- COMCreate("Outlook.Application")

# Create email
outMail = OutApp$CreateItem(0)

# Params 
outMail[["InternetCodePage"]] = "65001"
outMail[["To"]] = __your_outlook_email___
outMail[["subject"]] = "Subject_text"
outMail[["BodyFormat"]] = "2"
outMail[["HTMLBody"]] = bodyMail
outMail[["Attachments"]]$Add(__path_to_html_report__)

## send it                     
outMail$Send()

1 个答案:

答案 0 :(得分:1)

Outlook中的所有字符串属性(以及所有其他IDispatch友好的COM库)都是UTF-16。您有责任确保传递正确的数据。

另一方面,对所有正常ASCII范围之外的字符进行HTML编码是个好主意。这样代码页根本不重要。