R语言发email

最近用大型机运行R, 运行时间很长, 不知道什么时候跑完. 发现一个好用的包 mailR(https://github.com/rpremraj/mailR), 其实也可以用飞信的API 给自己发短信(都是非官方的, 以前用过, 今天再看都过期了).

那来介绍一下 mailR

mailR

SMTP 服务器(无需认证)

send.mail(from = "sender@gmail.com",
          to = c("Recipient 1 <recipient1@gmail.com>", "recipient2@gmail.com"),
          cc = c("CC Recipient <cc.recipient@gmail.com>"),
          bcc = c("BCC Recipient <bcc.recipient@gmail.com>"),
          # cc 和 bcc 都是接收者邮件, 我理解的是抄送,可以去掉, 保留to就可以了
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "aspmx.l.google.com", port = 25),
          authenticate = FALSE,
          encoding = "utf-8",
          send = TRUE)

SMTP 服务器(需认证)

send.mail(from = "[email protected]",
          to = c("[email protected]", "Recipient 2 <[email protected]>"),
          replyTo = c("Reply to someone else <[email protected]>")# 发送给其他人,可以没有这个参数
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

发送附件

send.mail(from = "[email protected]",
          to = c("[email protected]", "[email protected]"),
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE,
          attach.files = c("./download.log", "upload.log", #附件路径
          "https://dl.dropboxusercontent.com/u/5031586/How%20to%20use%20the%20Public%20folder.rtf"),
          file.names = c("Download log.log", "Upload log.log", "DropBox File.rtf"), # optional parameter
          file.descriptions = c("Description for download log", "Description for upload log", "DropBox File"), # optional parameter
          debug = TRUE)

具体的可以去https://github.com/rpremraj/mailR.
附上 163 邮箱的 SMTP 端口号

你可能感兴趣的:(email,R语言,电子邮件)