当前位置: 首页 > 工具软件 > Mailr > 使用案例 >

RPackage004---mailR自动发邮件

林鸿飞
2023-12-01

Intro

网上无意中看到别人的博客,感觉挺有意思的。玩一玩~
目前测试只发现163邮箱可以成功,而且要先开通smtp权限貌似

Code

# 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")#添加附件
)

Ref

[1] R语言之mailR包
[2] 用R语言发送邮件(mailR包)

 类似资料: