如何使用R发送HTML电子邮件 [英] How to send HTML email using R
问题描述
我搜索过SO,以及谷歌,似乎找不到我的问题的解决方案。我正在尝试使用sendmailR包在R内发送一个HTML格式的电子邮件。纯文本电子邮件工作正常,但无法从纯文本切换到HTML。
我的代码:
$ _ code> require(sendmailR)
from< - alertbot@companyname.com
message =< HTML>< body>< b>你好< / b>< /体>< / HTML>中
to = c(me@companyname.com)
subject =Test Monitor Alert
sendmail(from,to,subject,msg = msg,control = list (smtpServer =smtp-gw1.wal-mart.com),headers = list(Content-Type=text / html; charset = UTF-8; format = flowed))
我收到的电子邮件,但它的纯文本和电子邮件正文包含消息,而不是HTML格式的文本。请帮助。
这是可能的,cf https://stackoverflow.com/a/21930556/448145
只需添加:
msg < - mime_part(message)
msg [[headers]] [[Content-Type]]< - text / html
sendmail(from,to,subject, msg = msg,...)
I have searched SO and well as google and cannot seem to find a solution to my problem. I am trying to send a HTML formatted email within R using sendmailR package. The plain text email works just fine, but then am unable to switch from plain text to HTML.
My code:
require(sendmailR)
from <- "alertbot@companyname.com"
message = "<HTML><body><b>Hello</b></body></HTML>"
to = c("me@companyname.com")
subject = "Test Monitor Alert"
sendmail(from, to, subject, msg = msg,control=list(smtpServer="smtp-gw1.wal-mart.com"),headers=list("Content-Type"="text/html; charset=UTF-8; format=flowed"))
I do get the email, but its in plain text and the email body contains the message as is instead of the HTML formatted text. Please help.
This is possible, cf https://stackoverflow.com/a/21930556/448145 Just add:
msg <- mime_part(message)
msg[["headers"]][["Content-Type"]] <- "text/html"
sendmail(from, to, subject, msg = msg, ...)
这篇关于如何使用R发送HTML电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!