3

I'm trying to send emails from R using sendmailR package using the following code, which unfortunately fails :

## Set mail contents
from <- sprintf('<sendmailR@%s>', Sys.info()[4])
to <- '<slackline@gmail.com>'
subject <- 'Feeding Plots'
body <- list('Latest feeding graph', mime_part(feeding.plot,
                                               name = "feeding"))
## Set control parameters
control <- sendmail_options(verboseShow = TRUE, 
                            smtpServer ="smtp.gmail.com", 
                            smtpPort = 587, 
                            smtpSTARTTLS = '',
                            blocking = FALSE)
sendmail(from,
         to,
         subject,
         msg = body,
         control = control,
         headers)
<< 220 mx.google.com ESMTP xt1sm884721wjb.17 - gsmtp
>> HELO  kimura
<< 250 mx.google.com at your service
>> MAIL FROM:  <sendmailR@kimura>
<< 530 5.7.0 Must issue a STARTTLS command first. xt1sm884721wjb.17 - gsmtp
Error in wait_for(code) : 
  SMTP Error: 5.7.0 Must issue a STARTTLS command first. xt1sm884721wjb.17 - gsmtp

The sendmailR manual doesn't mention how to configures STARTTLS although it does indicate that additional arguments can be passed, which is why I have included the option smtpSTARTLS = '' based on whats mentioned in some other threads (here and here). I've tried playing with the argument for smtpSTARTTLS and setting it to TRUE but no joy.

Any pointers to documentation or solutions would be most welcome.

Thanks

Community
  • 1
  • 1
slackline
  • 2,295
  • 4
  • 28
  • 43

2 Answers2

3

As far as I understand it, sendmailR doesn't support any type of login to the SMTP server, hence, gmail is basically unusable. You can only use the package if you are within the right network and set up a server that is only reachable within the network I guess (i.e., one NOT using authentication).

The alternative is the mail package (in which you cannot use your own address).

The reference from the sendmailR documentation is:

SMTP AUTH is currently unsupported.

Henrik
  • 14,202
  • 10
  • 68
  • 91
  • Ok, thanks for that I hadn't realised TLS was related to authentication. I'd seen the `mail` package mentioned whilst reading up on `sendmailR`, will consider that but have [sendmail](http://www.sendmail.org/) installed on my system so may see if I can get them to work together. – slackline Jan 29 '14 at 13:46
2

You could give the new mailR package a shot that allows SMTP authorization: http://cran.r-project.org/web/packages/mailR/index.html

The following call should then work:

send.mail(from = "slackline@gmail.com",
          to = "slackline@gmail.com",
          subject = "Subject of the email",
          body = "Body of the email",
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "slackline", passwd = "PASSWORD", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)
Rahul Premraj
  • 1,595
  • 14
  • 13
  • Thanks for this clear example. We need to pay close attention to the smtp arguments' names which are not consistent across packages; user.name (not username) and passwd (not pw nor password). – Dominic Comtois Aug 04 '14 at 08:05
  • `mailR` does allow SMTP authentication, but unfortunately not STARTTLS (as described [here](https://r-bar.net/mailr-smtp-webmail-starttls-tls-ssl/)). – A. S. K. Jan 29 '20 at 20:31