2015-04-04 46 views
3

我想從Windows 7(家庭)機器上的R發送郵件。我嘗試下面的代碼從R發送郵件(郵件R)

send.mail(from = "[email protected]", 
      to = c("[email protected]"), 
      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 =私人): 無效 'ENVIR' 的說法

後,我試圖成立一個hmail服務器(具有本地域名和用戶帳戶和SMTP設置爲smtp.gmail.com:25)

send.mail(from = "[email protected]", 
      to = c("[email protected]"), 
      subject = "Subject of the email", 
      body = "Body of the email", 
      smtp = list(host.name = "mail.hmailserver.com", port = 25), 
      authenticate = FALSE, 
      send = TRUE) 

我仍然得到同樣的錯誤。任何幫助將不勝感激。由於VM

+0

嘗試[啓用](https://www.google.com/settings/security/lesssecureapps)爲您的谷歌帳戶的SMTP訪問。 – m0nhawk 2015-04-04 19:21:48

回答

1

如果您的Gmail帳戶propertly設置(如mOnhawk建議),那麼這種形式應該爲smtp列表工作:

smtp = list(host.name = "smtp.gmail.com", port = 465, 
         ssl=TRUE, user.name = "[email protected]", 
         passwd = "my password) 
+0

thx完美!這似乎對我有用。 – 2015-04-05 17:25:39

0

你可以試試下面的例子:

library(mail) 

to <- "[email protected]" 
subject <- "mail of R" 
msg <- paste("Testing!") 
sendmail(to, subject , msg) 

但只允許你發送每 20日的電子郵件,我希望你覺得它有用。

好運!

0

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

我試過我的公司電子郵件和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 
0
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 
+1

請看[answer] – clinomaniac 2018-02-20 21:58:28