rpremraj / mailR

A utility to send emails from the R programming environment
http://rpremraj.github.io/mailR/
190 stars 57 forks source link

Issue sending mail from crontab #90

Open deschsimon opened 4 years ago

deschsimon commented 4 years ago

I really like this package and I have succesfully used it to send emails via an Exchange server using code that looks like this:

email <- send.mail(from = me@exchange-server.com,
                   to = you@some-server.com, 
                   subject = 'Important message',
                   body = /path/to/Rmd_output.html, 
                   html=T,
                   inline=T,
                   authenticate = TRUE,
                   smtp = list(host.name = smtp.exchange-server.local, port = 587,
                               user.name = me@exchange-server.com, passwd = absolutely.sec.pwd, tls = T),
                   debug = T,
                   send = F)
email$send()

However, if I move the script sending the email to a crontab and try to let it run automatically, I do get the error

Nov 20 20:56:09 myserver sSMTP[27150]: Creating SSL connection to host
Nov 20 20:56:09 myserver sSMTP[27150]: SSL connection using ECDHE_RSA_AES_128_GCM_SHA256
Nov 20 20:56:10 myserver cron[524]: sendmail: 550 5.7.60 SMTP; Client does not have permissions to send as this sender
Nov 20 20:56:10 myserver sSMTP[27150]: 550 5.7.60 SMTP; Client does not have permissions to send as this sender
Nov 20 20:56:10 myserver CRON[27135]: (root) MAIL (mailed 1053 bytes of output but got status 0x0001 from MTA#012)

Running the script from the commandline (using either Rscript or shebang line from littler) works fine. And so does sending from with R.

Here is my sessionInfo():

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_US.UTF-8           LC_COLLATE=en_US.UTF-8       
 [5] LC_MONETARY=en_US.UTF-8       LC_MESSAGES=en_US.UTF-8      
 [7] LC_PAPER=en_US.UTF-8          LC_NAME=en_US.UTF-8          
 [9] LC_ADDRESS=en_US.UTF-8        LC_TELEPHONE=en_US.UTF-8     
[11] LC_MEASUREMENT=en_US.UTF-8    LC_IDENTIFICATION=en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xlsx_0.6.1      mailR_0.6       lubridate_1.7.4 rvest_0.3.4    
[5] xml2_1.2.2      httr_1.4.1     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3        xlsxjars_0.6.1    R.methodsS3_1.7.1 R6_2.4.0         
 [5] magrittr_1.5      stringi_1.4.3     R.oo_1.23.0       R.utils_2.9.0    
 [9] tools_3.4.4       stringr_1.4.0     compiler_3.4.4    rJava_0.9-11

Any idea on how to solve this is highly appreciated!!! Thank you!