On 10-May-05 Fernando Saldanha wrote: > Is there a way to have an R program send an email? > > Something like this: > > address <- '[EMAIL PROTECTED]' > text <- 'This is the email body' > send.email(address, text)
As Brian Ripley said, this is highly OS-specific! On the other hand, studying 'bug.report' may be excessive. *Provided* you are using a Unixoid system (Unix, Linux, and as far as I know Mac OS X), you will almost certainly have the 'mail' command which can be readily used for a simple email such as the one you describe above. At the system level, a possible command could be mail -s "subject of mail" [EMAIL PROTECTED] << EOT "This is the email body" EOT so all you need is an R function which binds all these elements together. For example, the following works on my Linux system: send.mail<-function(addr,subject="Mail from R", text="empty text"){ mail.cmd<-paste("mail ", "-s \"",subject,"\" ", addr, " << EOT &\n", text,"\n", "EOT", sep="",collapse="") system(mail.cmd,intern=FALSE) } For example, with: send.mail("[EMAIL PROTECTED]", subject="Message from R: At Last!", text="Good Morning!\nI've been busy all night.\nIt's finished." ) after a minute or two for delivery I get the following message delivered on my machine: From [EMAIL PROTECTED] Tue May 10 09:50:27 2005 Date: Tue, 10 May 2005 09:49:50 +0100 From: Ted Harding <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Subject: Message from R: At Last! Good Morning! I've been busy all night. It's finished. I've specified "intern=FALSE" explicitly (though it is the default), since if you set it TRUE (e.g. in order for R to verify the sending) then R will hang until it receives the feedback from the command (the "&" in "EOT &\n" puts the job in the background so there is no delay). Hoping this helps! (Of course, if you're not a unixoid, this is probably no use to you at all, and I have no idea how to do anything similar in Windows). Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 10-May-05 Time: 10:01:21 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html