网上无意中看到别人的博客,感觉挺有意思的。玩一玩~
目前测试只发现163邮箱可以成功,而且要先开通smtp权限貌似
# MyEmail.R
tryCatch({
library(mailR)
}, error = function(e) {
print("NO mailR Packages")
print(conditionMessage(e))#打印错误信息
install.packages("mailR")#没有包则安装
}, finally = {
library(mailR)
})
sender <- "l2532101023@163.com"#发送的邮箱
recipients <- c("l2532101023@163.com") #接受者的邮箱
send.mail(
from = sender,
to = recipients,
subject = "Try mailR package",
#邮件主题
body = "Get it",
smtp = list(
host.name = "smtp.163.com",
port = 465,
user.name = "l2532101023@163.com",
passwd = "******",
ssl = TRUE
),
authenticate = TRUE,
send = TRUE,
encoding = "utf-8",
attach.files = c("./Learning_R/附件.txt")#添加附件
)