0

I'm able to send emails using the following code.

OutlookForSend = RDCOMClient::COMCreate("Outlook.Application")
emailToSend = OutlookForSend$CreateItem(0)
emailToSend[["subject"]] = "Subject"
emailToSend[["HTMLBody"]] = bodyToSend
emailToSend[["To"]] = "Email"
emailToSend$Send()

However, I don't have outlook installed, in the server machine but still need to send emails.

I'm able to achieve the same using the package mailer in Python , what is the best way to achieve the same in R.

Thanks

nsivakr
  • 1,565
  • 2
  • 25
  • 46

2 Answers2

0

Any SMTP client implemented in R will do the job. Check out this one: Rmailer

From their example:

library(Rmailer)


message <- c(
  "Hey,",
  "",
  "I have a nice pic for you!",
  "",
  "Best",
  "C."
)


settings <- list(
  server = "smtp.example.org",
  username = "user",
  password = "password"
)


## send message:
sendmail(
  from = "sender@example.org",
  to = "receiver@example.org",
  subject = "Good news!",
  msg = message,
  smtpsettings = settings,
  attachment = "nice_pic.jpg"
)
Wojciech Kulma
  • 6,186
  • 3
  • 18
  • 27
0

Solved the problem, using mailR package and it works well.

library(mailR)
send.mail(from = "email@company.com",
          to = "email@company.com",
          subject = subjectToSend ,
          body = bodyToSend,
          html = TRUE,
          smtp = list(host.name = "smtp.company.com", port = 25), 
          send = TRUE)
nsivakr
  • 1,565
  • 2
  • 25
  • 46