我想发送来自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)
Run Code Online (Sandbox Code Playgroud)
当我执行此脚本时,我的R会话挂起.有什么想法可能会发生什么?
alk*_*989 43
如果您需要能够使用带身份验证的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)
Run Code Online (Sandbox Code Playgroud)
Sar*_*rah 21
我刚试了一下,它对我有用.
我唯一的区别是我使用<>作为from和to:
from = "<email1@dal.ca>"
to = "<email2@gmail.com>"
Run Code Online (Sandbox Code Playgroud)
和我的邮件控制不同,我用过
control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
Run Code Online (Sandbox Code Playgroud)
Cod*_*pra 13
很抱歉碰到这个帖子.如果您想使用Microsoft Outlook从R发送电子邮件,下面是使用该RDCOMClient软件包的方法.我自己花了很多时间试图找到答案.我认为在这个线程中为用户提供这个解决方案会很有用.
完全归功于@agstudy,他在此链接中提供了原始解决方案 - 通过Outlook在R中发送电子邮件
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()
Run Code Online (Sandbox Code Playgroud)
小智 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 )
Run Code Online (Sandbox Code Playgroud)
有一个名为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)
Run Code Online (Sandbox Code Playgroud)