Search code examples
rgmail

Receive email notification when script ends


How easy is it to send e-mail through R?

using this

> library(sendmailR)
> 
> 
> from <- "[email protected]"
> to <- "[email protected]"
> subject <- "Performance Result"
> body <- "This is the result of the test:"                     
> mailControl=list(smtpServer="snmpt server address")
> 
> sendmail(from=from,to=to,subject=subject,msg=body,control=list(smtpServer="ASPMX.L.GOOGLE.COM"))

I receive this error:

Error in wait_for(code) : 
  SMTP Error: 5.5.2 Syntax error. jp9si1521863wjb.204 - gsmtp

I guess I should make something from the side of gmail but what should I have to make?

I tried also this for gmail using real address but I didn't receive any error but neither any e-mail

library(mailR)
sender <- "[email protected]" # Replace with a valid address
recipients <- c("[email protected]") # Replace with one or more valid addresses
email <- send.mail(from = sender,
to = recipients,
subject="Subject of the email",
body = "Body of the email",
smtp = list(host.name = "aspmx.l.google.com", port = 25),
authenticate = FALSE,
send = FALSE)

Solution

  • It works for me with slightly different smtp settings (host name, port and ssl and addition of user.name and passwd) and also with 'authenticate' and 'send' changed to TRUE.

    library(mailR)  
    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 = sender, 
                        passwd = "senders_password", ssl = TRUE),
            authenticate = TRUE,
            send = TRUE)