从 R (mailR) 发送邮件

sending mail from R (mailR)

我正在尝试从 windows 7(家用)机器上的 R 发送邮件。我尝试了以下代码

send.mail(from = "mymailid@gmail.com",
          to = c("mymailid@gmail.com"),
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "myuserid", passwd = "my password", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

我收到以下错误: ls(envir = envir, all.names = private) 错误: 无效 'envir' 参数

之后我尝试设置一个 hmail 服务器(使用本地域名和用户帐户,并为 smtp.gmail.com:25 设置 smtp)

send.mail(from = "localuser@localdomain.local",
          to = c("mymailid@gmail.com"),
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "mail.hmailserver.com", port = 25),
          authenticate = FALSE,
          send = TRUE)

我仍然遇到同样的错误。任何帮助将不胜感激。谢谢 vm

如果您的 gmail 帐户设置正确(如 mOnhawk 所建议的),那么此表单应该适用于 smtp 列表:

smtp = list(host.name = "smtp.gmail.com", port = 465,
                        ssl=TRUE, user.name = "mymailid@gmail.com",
                        passwd = "my password)

如果您使用的是 gmail 帐户,您可能需要允许安全性较低的应用程序访问您的帐户,使用此 link https://www.google.com/settings/security/lesssecureapps

如果您还有两步验证,您还需要停用它。

您可以试试下面的例子:

library(mail)

to <-  "albert.physik@gmail.com"
subject <- "mail of R"
msg <- paste("Testing!")
sendmail(to, subject , msg)

但是每天只允许发送20封邮件 我希望你觉得它有用。

运气好!

您是否使用空字符串作为正文?

我尝试使用公司电子邮件和 gmail。当我把

body = "", # quotation marks with nothing in between

它产生

Error in ls(envir = envir, all.names = private) : invalid 'envir' argument

虽然这有效:

body = " ", # adding a space there

完全不知道为什么...如果您碰巧有空字符串,这可能会有所帮助。

主题为空字符串不会造成问题:

subject = "", # quotation marks with nothing in between
i am trying to send email using RDCOMClient and here is the code

library(RDCOMClient)

emails <- paste("emailid")
## init com api
OutApp <- COMCreate("Outlook.Application")
## create an email 
outMail = OutApp$CreateItem(0)
## configure  email parameter 
outMail[["To"]] = emails
outMail[["Cc"]] = "emailid"
outMail[["subject"]] = "Monthly Report for Compliance"
outMail[["body"]] = paste(" Please find the monthly report  completed for ",Sys.Date(),
                          ".\n\n instrument file is saved at:\n G:\Data Science\Monthly Check - Westlake\Instruments and Issuers Compliance List
                          "
                          )

outMail[["attachments"]]$Add("G:\Data Science\Monthly Check - Westlake\Instruments and Issuers Compliance List\Instruments_tracked-.02202018.csv")    
outMail$Send()

I get the below error
<checkErrorInfo> 80020009 
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567