how do you send email from R

Solution 1:

If you need to be able to use an smtp server with authentication you can use the mailR package.

For example using gmail's smtp server:

library(mailR)
sender <- "[email protected]"
recipients <- c("[email protected]")
send.mail(from = sender,
          to = recipients,
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, 
                      user.name = "[email protected]",            
                      passwd = "YOURPASSWORD", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

Solution 2:

I just tried it out, and it worked for me.

My only differences were I used <> for the from and to:

from = "<[email protected]>"
to = "<[email protected]>"

and my mail control was different, I used

control=list(smtpServer="ASPMX.L.GOOGLE.COM"))

Solution 3:

Sorry for bumping up this thread. If you want to send email from R using Microsoft outlook, below is the way to go using the RDCOMClient package. I myself spent a lot of time trying to find an answer on this. I thought it would be useful to have this solution too in this thread for users.

Full credit to @agstudy who provided the original solution in this link - Sending email in R via outlook

library (RDCOMClient)

OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "[email protected]"
outMail[["subject"]] = "Test Subject"
outMail[["body"]] = "Body of email"               
outMail$Send()

Solution 4:

library(mailR)
sender <- "[email protected]"

recipients <- c("[email protected]","[email protected]")

send.mail(
    from = sender, 
     to = recipients, 
     subject="Cash_Collected_Bank_transfer",
     Sys.Date(),
     "{}", body = Summary1, encoding = "utf-8", smtp = 
         list(host.name = "smtp.gmail.com", port = 465, 
         user.name="[email protected]", passwd="abc@1234", ssl=TRUE), 
     authenticate = TRUE, send = TRUE ,
     attach.files = c(path2), html = TRUE , inline = TRUE )