[R] Email out of R (code)

Daniel Malter daniel at umd.edu
Tue May 17 22:44:20 CEST 2011


Hi all, 

I thought I would post code to send an email out of R. The code uses
Grothendieck and Bellosta's interface package rJython for executing Python
from R. The code itself provides basic email functionality for email servers
requiring authentication. It should be easy to extend it (e.g., for sending
attachments). I hope it's useful.

require(rJython)
rJython <- rJython()
rJython$exec( "import smtplib" )
rJython$exec("from email.MIMEText import MIMEText")
rJython$exec("import email.utils")

mail<-c(
#Email settings
"fromaddr = 'sender email address'", 
"toaddrs  = 'recipient email address'",
"msg = MIMEText('This is the body of the message.')",
"msg['From'] = email.utils.formataddr(('sender name', fromaddr))",
"msg['To'] = email.utils.formataddr(('recipient name', toaddrs))",
"msg['Subject'] = 'Simple test message'",

#SMTP server credentials
"username = 'sender login'",
"password = 'sender password'",

#Set SMTP server and send email, e.g., google mail SMTP server
"server = smtplib.SMTP('smtp.gmail.com:587')",
"server.ehlo()",
"server.starttls()",
"server.ehlo()",
"server.login(username,password)",
"server.sendmail(fromaddr, toaddrs, msg.as_string())", 
"server.quit()")

jython.exec(rJython,mail)



Best,
Daniel

--
View this message in context: http://r.789695.n4.nabble.com/Email-out-of-R-code-tp3530671p3530671.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list