在Windows上使用sendmailR

Tal*_*ili 20 email gmail smtp r sendmailr

我正在尝试使用以下代码在Windows上运行sendmailR:

## Not run: 
from <- "<tal.galili@gmail.com>" # sprintf("<sendmailR@\\%s>", Sys.info()[4])
to <- "<tal.galili@gmail.com>"
subject <- "Hello from R"
body <- list("It works!", mime_part(iris))
sendmail(from, to, subject, body,
         control=list(smtpServer="ASPMX.L.GOOGLE.COM."))
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

Error in socketConnection(host = server, port = port, blocking = TRUE) : 
  cannot open the connection
In addition: Warning message:
In socketConnection(host = server, port = port, blocking = TRUE) :
  smtp.gmail.com tal.galili@gmail.com:statisfun:25 cannot be opened
Run Code Online (Sandbox Code Playgroud)

这里的答案为Linux提供了解决方案,我将非常感谢Windows用户的建议.

谢谢.

Rah*_*raj 7

您可以为新的mailR包提供一个镜头:http://cran.r-project.org/web/packages/mailR/index.html

然后应该执行以下调用:

send.mail(from = "tal.galili@gmail.com",
          to = "tal.galili@gmail.com",
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "tal.galili", passwd = "PASSWORD", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)
Run Code Online (Sandbox Code Playgroud)


Gia*_*ear 5

我曾经使用这些行通过 R 发送电子邮件。

假设您的电子邮件tal.galili@gmail.com使用的是windows OS(我的操作系统)

library(sendmailR)

# 1 case
from <- sprintf("<sendmailR@%s>", Sys.info()[4]) 
to <- "<tal.galili@gmail.com>" 
subject <- "Hello from R" 
msg <- "my first email" 
sendmail(from, to, subject, msg,control=list(smtpServer="ASPMX.L.GOOGLE.COM")) 

# 2 case
from <- sprintf("<tal.galili@gmail.com>", Sys.info()[4]) 
to <- "<tal.galili@gmail.com>" 
subject <- "Hello from R" 
msg <- "my first email" 
sendmail(from, to, subject, msg,control=list(smtpServer="ASPMX.L.GOOGLE.COM")) 
Run Code Online (Sandbox Code Playgroud)