我想从R发送电子邮件。这是我到目前为止所做的:
library(sendmailR)
from <- "eamil@example.com"
to <- "email2@example.com"
subject <- "Performance Result"
body <- "This is the result of the test:"
mailControl=list(smtpServer="snmpt server address")
sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)
当我执行此脚本时,我的R会话挂起。任何想法可能会发生什么?
答案 0 :(得分:39)
如果您需要能够使用带身份验证的smtp服务器,则可以使用mailR
包。
例如使用gmail的smtp服务器:
library(mailR)
sender <- "SENDER@gmail.com"
recipients <- c("RECIPIENT@gmail.com")
send.mail(from = sender,
to = recipients,
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "smtp.gmail.com", port = 465,
user.name = "YOURUSERNAME@gmail.com",
passwd = "YOURPASSWORD", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
答案 1 :(得分:19)
我刚尝试过,它对我有用。
我唯一的区别是我用过&lt;&gt;对于来自和:
from = "<email1@dal.ca>"
to = "<email2@gmail.com>"
我的邮件控件不同,我用了
control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
答案 2 :(得分:10)
很抱歉打破了这个帖子。如果您想使用Microsoft Outlook从R发送电子邮件,下面是使用RDCOMClient
包的方法。我自己花了很多时间试图找到答案。我认为在这个线程中为用户提供这个解决方案会很有用。
完全赞同@agstudy,他在此链接中提供了原始解决方案 - Sending email in R via outlook
library (RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "test@test.com"
outMail[["subject"]] = "Test Subject"
outMail[["body"]] = "Body of email"
outMail$Send()
答案 3 :(得分:5)
library(mailR)
sender <- "abc@gmail.com"
recipients <- c("bcd@gmail.com","xyz@gmail.com")
send.mail(
from = sender,
to = recipients,
subject="Cash_Collected_Bank_transfer",
Sys.Date(),
"{}", body = Summary1, encoding = "utf-8", smtp =
list(host.name = "smtp.gmail.com", port = 465,
user.name="abc@gmail.com", passwd="abc@1234", ssl=TRUE),
authenticate = TRUE, send = TRUE ,
attach.files = c(path2), html = TRUE , inline = TRUE )
答案 4 :(得分:0)
如果您希望使用服务器内部解决方案,则可以致电linux sendmail。
EMAIL <- myEmail@gmail.com
cmd <- 'subject="Info server";body="This is an email"'
cmd <- paste("echo -e \"Subject:${subject}\n${body}\" | /usr/sbin/sendmail -t \"", EMAIL, "\"")
system(cmd)
答案 5 :(得分:0)
有一个名为emayili的新程序包,它具有两个非常有趣的承诺:
这似乎是早期阶段,但仍然很有希望。发送电子邮件非常简单:
devtools::install_github("datawookie/emayili")
library(emayili)
library(dplyr)
email <- envelope() %>%
from("alice@yahoo.com") %>%
to("bob@google.com") %>%
subject("This is a plain text message!") %>%
body("Hello!")
smtp <- server(host = "smtp.gmail.com",
port = 465,
username = "bob@gmail.com",
password = "bd40ef6d4a9413de9c1318a65cbae5d7")
smtp(email, verbose = TRUE)
答案 6 :(得分:0)
我发现Ubuntu中最简单的方法是在R中运行一个内衬Terminal命令。 不需要密码。
try(system(“ mutt -s'Run is complete。'youremail@anymail.com
在此之前,您需要在终端中安装mutt。