how do you send email from R

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)

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"))

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()

Tags:

R