From pgilbert at bank-banque-canada.ca  Wed Jul 30 12:41:15 2003
From: pgilbert at bank-banque-canada.ca (Paul Gilbert)
Date: Wed Jul 30 17:41:33 2003
Subject: [Rd] Re: [R] Sending emails from R under Windows
In-Reply-To: <20030730101318.B23385@jessie.research.bell-labs.com>
References: <8D0F30FE2EB3314182D4A33F738BB19D063E6E@sqlsrvr.evocapital.com>
	<20030730101318.B23385@jessie.research.bell-labs.com>
Message-ID: <3F27E71B.1090004@bank-banque-canada.ca>

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
> }
>


[Rd] Re: [R] Sending emails from R under Windows
Paul Gilbert