我只是尝试使用mailR软件包通过我的Gmail帐户向R发送电子邮件,但它似乎无效。
我收到此错误:
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : org.apache.commons.mail.EmailException: Sending the email to the following server failed : aspmx.l.google.com:25
以下是匿名gmail地址的代码。
install.packages("mailR")
library(mailR)
sender <- "sender@gmail.com" # Replace with a valid address
recipients <- c("receiver1@gmail.com") # Replace with one or more valid addresses
email <- send.mail(from = sender,
to = recipients,
subject="Subject of the email",
body = "Body of the email",
smtp = list(host.name = "aspmx.l.google.com", port = 25),
authenticate = FALSE,
send = FALSE)
email$send() # execute to send email
答案 0 :(得分:1)
我终于成功了!您必须在Google上授权该应用。这个链接真的帮助了我:https://medium.com/airbnb-engineering/using-googlesheets-and-mailr-packages-in-r-to-automate-reporting-c09579e0377f