Hi Prarthana,
Install mailR and load the package.
install.packages("mailR", dep = T)
library(mailR)
Next, follow the below format to send mail using SMTP without authentication.
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>"),
subject = "Subject of the email",
body = "Body of the email",
smtp = list(host.name = "aspmx.l.google.com", port = 25),
authenticate = FALSE,
send = TRUE)
To send a mail with authentication using SMTP, follow the below format.
send.mail(from = "sender@gmail.com",
to = c("recipient1@gmail.com", "Recipient 2 <recipient2@gmail.com>"),
replyTo = c("Reply to someone else <someone.else@gmail.com>")
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)
In the above two formats of Sendmail, the structure follows the same as every email i.e from, to, cc, bcc, subject, body.
smtp port and host differs in both the formats due to authentication and other factors.