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
Sending emails from R under Windows
3 messages · David Khabie-Zeitoune, Jason Turner, David James
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 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-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 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