Skip to content
Prev 69460 / 398513 Next

Does R have a command for sending emails?

At the risk of beating this to death ... if you use Outlook mail on Windows,
you can create a simple 'sendmail' vbscript:

' ==== start ===
Dim pOutlook, pMail, fso, f

Set pOutlook = CreateObject("Outlook.Application")
Set pMail = pOutlook.CreateItem(olMailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(WScript.Arguments(2), 1)

With pMail
   .To = WScript.Arguments(0)
   .Subject = WScript.Arguments(1)
   .Body = f.ReadAll()
   .Send
End With

f.Close()
' ==== end ====

And then call this from R:

send.mail <- function(addr, subject, source.file) {
   mail.cmd <-
paste(paste(Sys.getenv("SystemRoot"),"/system32/wscript.exe",sep=""),
      "sendmail.vbs", addr, dQuote(subject), source.file, sep=" ")
      
   system(mail.cmd, intern=F)
}

Note that if sendmail.vbs is not in the current R working directory you have
to provide a full path.
Norm Olsen 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Fernando Saldanha
Sent: Tuesday, May 10, 2005 6:28 AM
To: Submissions to R help
Subject: Re: [R] Does R have a command for sending emails?

I want to thank all who have offered help on this topic. I was able to
create a very simple email function that I have tested to work under Windows
XP Professional and R 2.1.0. It uses Blat version 1.9.4.

send.mail<-function(addr, subject, source.file) {
  mail.cmd <- paste("Blat", source.file, "-subject", dQuote(subject), "-to",
addr, separator = " ", collapse = "")
  
  system(mail.cmd, intern = FALSE)
}

The string source.file must have double backslashes instead of single
backslashes. For example:

C:\\myfolder

One must first install Blat version 1.9.4, available at 

http://www.blat.net/194/.

All that is needed is to unzip the downloaded file (Blat194.zip) and copy
Blat.exe to a folder in the path. The other files inside Blat194.zip can be
discarded.

FS
On 5/10/05, Frank E Harrell Jr <f.harrell at vanderbilt.edu> wrote:
______________________________________________
R-help at 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