1

我无法以 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()
4

1 回答 1

1

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

附带说明一下,对正常 ASCII 范围之外的所有字符进行 HTML 编码是个好主意。这样代码页就完全不重要了。

于 2016-09-14T16:47:53.477 回答