I have a scheduled an R script running from a windows machine.
After it finishes, I wish this script to automatically send an email with some log file attached.
Using shell()
with some other scripts may be possible, but I was wondering if there is a better solution within R.
Thanks.
sendmailR works for me on Windows 7. I referenced http://cran.es.r-project.org/web/packages/sendmailR/sendmailR.pdf
smtpServer= info for Outlook 2010 is in File -> Account Settings -> Account Settings -> double click your account -> text in "Server" box
In addition, multiple files can be sent by adding another mime_part to the msg list as follows (I also condensed it):
Have you looked into the
sendmailR
package yet? It allows SMTP to submit a message and you could probably edit the function to allow an attachment. Then again, if its only one log file it might just be worth it to useshell()
as you mentioned.Would you settle for a twitter message? You could use Rcurl to post an update to twitter, which can then be forwarded to your cell phone as a text, or to your email via the notification settings.
See here: http://www.sakana.fr/blog/2007/03/18/scripting-twitter-with-curl/
For Windows one might parse together a VB-Script (see e.g. http://www.paulsadowski.com/wsh/cdo.htm ) and then call it via shell.
This might look like this:
Use mailR - it works with authentication, attachments, it automatically send txt message along with html and more.
mailR
requires rJava which can be a bit of a pain sometimes. On windows I haven't had any problems. On ubuntu this solved the one issue I've had:in R
(if you have trouble with rJava - try
sudo R CMD javareconf
in terminal)mailR
is easy to work with and well documented on the github page.Example from the documentaion
Note: your smtp server might find excessive use suspicious. This is the case with e.g. gmail. So after sending a few mails you probably have to log in to the gmail account and see if the account has been temporarily disabled. Also note that if you use a gmail account with two-factor authentication you need to use an application specific password.
Just want to remind people who wants self-notifying feature of a service called twilio, they provide free service to send sms to your own cellphone. A walk-through using R is available here https://dreamtolearn.com/ryan/data_analytics_viz/78
An example code is attached, just replace the credentials with the ones of your own.