how do you send email from R

后端 未结 8 923
情书的邮戳
情书的邮戳 2020-11-29 18:11

I want to send emails from R. This is what I have so far:

library(sendmailR)


from <- \"eamil@example.com\"
to <- \"email2@example.com\"
subject <-         


        
8条回答
  •  长情又很酷
    2020-11-29 18:49

    There are two ways to send an email via Gmail, anonymized or authenticated. Here is the code for anonymized:

    library(mailR)
    send.mail(from = "sender@gmail.com",
          to = c("Recipient 1 ", "recipient2@gmail.com"),
          cc = c("CC Recipient "),
          bcc = c("BCC Recipient "),
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "aspmx.l.google.com", port = 25),
          authenticate = FALSE,
          send = TRUE)
    

    Make sure the recipient emails are Gmail too. It most likely goes to the spam folder in the Gmail account so make sure to mark it "not spammed".

    You can find more info here.

提交回复
热议问题