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



我在UTF-8格式的电子邮件正文文本中遇到了麻烦。我的降价报告是好的,脚本工作时,从RStudio运行-即正文文本是在UTF-8。我的问题是,当我从命令行运行脚本时,我的电子邮件消息使用windows-1252编码,这是我不想要的。

我如何设置我的代码来指定我的邮件头有内容类型UTF-8?InternetCodepage至少不工作

R-code如下:

## 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()

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

另一方面,对正常ASCII范围之外的所有字符进行html编码是一个好主意。这样代码页就无关紧要了。

相关内容

最新更新