Hi Does anyone know of any R routines to send emails from R, under Windows? I thought about writing such a facility using the R(D)COM package to drive e.g. MS Outlook, but I don't want to reinvent the wheel. I have found a function Sys.mail in the library syskern, but this only works under Unix by shelling out a mail command. Thanks, David
David Khabie-Zeitoune wrote:> Does anyone know of any R routines to send emails from R, under Windows? > I thought about writing such a facility using the R(D)COM package to > drive e.g. MS Outlook, but I don't want to reinvent the wheel. I have > found a function Sys.mail in the library syskern, but this only works > under Unix by shelling out a mail command.I've used R to call a perl script to handle the mailing; both the raw mail commands, plus the compression of attachments, mime encoding of plots or data files, etc. Haven't got it handy, but (being perl) it should be very platform independant doing things that way. You could run the script either as a system() command, or possibly using the RSperl library from Omegahat (haven't used the latter - just speculating). Check out the MIME::Parser and Mail::Sender perl modules. Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz
David, I second Jason's good suggestion, with the additional comment that if you have Outlook on the same machine, a short VBScript through the Windows Cscript / Wscript facility should be another sufficient alternative to consider. An example of this can be found at http://www.mindspring.com/~tflynn/excelvba2.html#Send_Mail I use something similar to this, and even though it is written for Excel VBA, the logic should transfer over to VBScript. And as Jason specifically says, system() provides the interface you would need to launch the script. Hope that helps. Bill ---------------------------------------- Bill Pikounis, Ph.D. Biometrics Research Department Merck Research Laboratories PO Box 2000, MailDrop RY33-300 126 E. Lincoln Avenue Rahway, New Jersey 07065-0900 USA v_bill_pikounis at merck.com Phone: 732 594 3913 Fax: 732 594 1565> -----Original Message----- > From: Jason Turner [mailto:jasont at indigoindustrial.co.nz] > Sent: Wednesday, July 30, 2003 6:33 AM > To: David Khabie-Zeitoune > Cc: R-Help > Subject: Re: [R] Sending emails from R under Windows > > > David Khabie-Zeitoune wrote: > > Does anyone know of any R routines to send emails from R, > under Windows? > > I thought about writing such a facility using the R(D)COM package to > > drive e.g. MS Outlook, but I don't want to reinvent the > wheel. I have > > found a function Sys.mail in the library syskern, but this > only works > > under Unix by shelling out a mail command. > > I've used R to call a perl script to handle the mailing; both the raw > mail commands, plus the compression of attachments, mime encoding of > plots or data files, etc. Haven't got it handy, but (being perl) it > should be very platform independant doing things that way. > > You could run the script either as a system() command, or > possibly using > the RSperl library from Omegahat (haven't used the latter - just > speculating). > > Check out the MIME::Parser and Mail::Sender perl modules. > > Cheers > > Jason > -- > Indigo Industrial Controls Ltd. > 64-21-343-545 > jasont at indigoindustrial.co.nz > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.
David Khabie-Zeitoune wrote:> Hi > > Does anyone know of any R routines to send emails from R, under Windows? > I thought about writing such a facility using the R(D)COM package to > drive e.g. MS Outlook, but I don't want to reinvent the wheel. I have > found a function Sys.mail in the library syskern, but this only works > under Unix by shelling out a mail command. > > Thanks, > > David > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpThe R function sendEmail() below uses the RDCOMClient package to control Outlook or Echange -- more precisely, it interfaces to Microsoft's Collaboration Data Objects (CDO). (Please note that I don't use Windows for email, so I couldn't test the function.)> sendEmail(ema = "r-help at r-project.org",name = "R-help mailing list", subject = "How to send Email from R using the RDCOMClient" msgBody = "here is the body of the message") The package RDCOMClient is available at http://www.omegahat.org/RDCOMClient. "sendEmail" <- function(ema, name, subject, msgBody, deliverNow = TRUE) { require(RDCOMClient) ema <- paste("SMPT:", ema, sep="") ## prepend protocol to address ## create an e-mail session session <- COMCreate("Mapi.Session") session$Logon() ## add a message to the outbox collection of messages outbox <- session[["Outbox"]] msg <- outbox[["Messages"]]$Add(subject, msgBody) ## add recipient's name (TODO: addMultiple() or loop, if many recipients) msg[["Recipients"]]$Add(name, ema) msg$Send() if(deliverNow) msg$DeliverNow() session$Logoff() ## wrap up } -- David A. James Statistics Research, Room 2C-253 Phone: (908) 582-3082 Bell Labs, Lucent Technologies Fax: (908) 582-3340 Murray Hill, NJ 09794-0636
Any chance a utility like this could be incorporated in base and used by bug.report. That would make the same utility available to everyone, rather than us all inventing the same thing over again. Paul Gilbert David James wrote:> David Khabie-Zeitoune wrote: > >>Hi >> >>Does anyone know of any R routines to send emails from R, under Windows? >>I thought about writing such a facility using the R(D)COM package to >>drive e.g. MS Outlook, but I don't want to reinvent the wheel. I have >>found a function Sys.mail in the library syskern, but this only works >>under Unix by shelling out a mail command. >> >>Thanks, >> >>David >> >>______________________________________________ >>R-help@stat.math.ethz.ch mailing list >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > The R function sendEmail() below uses the RDCOMClient package > to control Outlook or Echange -- more precisely, it interfaces to > Microsoft's Collaboration Data Objects (CDO). (Please note that > I don't use Windows for email, so I couldn't test the function.) > > >>sendEmail(ema = "r-help@r-project.org", > > name = "R-help mailing list", > subject = "How to send Email from R using the RDCOMClient" > msgBody = "here is the body of the message") > > The package RDCOMClient is available at http://www.omegahat.org/RDCOMClient. > > "sendEmail" <- > function(ema, name, subject, msgBody, deliverNow = TRUE) > { > require(RDCOMClient) > > ema <- paste("SMPT:", ema, sep="") ## prepend protocol to address > > ## create an e-mail session > session <- COMCreate("Mapi.Session") > session$Logon() > > ## add a message to the outbox collection of messages > outbox <- session[["Outbox"]] > msg <- outbox[["Messages"]]$Add(subject, msgBody) > > ## add recipient's name (TODO: addMultiple() or loop, if many recipients) > msg[["Recipients"]]$Add(name, ema) > msg$Send() > if(deliverNow) > msg$DeliverNow() > > session$Logoff() ## wrap up > } >
Thanks to everyone that responded on this subject -- 4 responses with 4 separate solutions to the problem! Thanks especially to Gabor Grothendieck for introducing me to "blat", the freeware emailer executable which was the solution I implemented in the end, as it avoided problems caused by Outlook's security features getting in the way (my COM instance of Outlook got very paranoid when R tried to send mails and kept popping up with warning messages which meant I could not really use this non-interactively). Anyway, thanks again. -----Original Message----- From: David Khabie-Zeitoune Sent: 29 July 2003 16:59 To: r-help at r-project.org Subject: [R] Sending emails from R under Windows Hi Does anyone know of any R routines to send emails from R, under Windows? I thought about writing such a facility using the R(D)COM package to drive e.g. MS Outlook, but I don't want to reinvent the wheel. I have found a function Sys.mail in the library syskern, but this only works under Unix by shelling out a mail command. Thanks, David ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help