Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email in R via outlook [closed]

Tags:

r

outlook

How can I send emails in R via Outlook?

All the examples of sendmailR use the gmail server, but I cannot do that.

like image 433
user3022875 Avatar asked Nov 07 '14 23:11

user3022875


People also ask

Can R send an email?

R has a package for sending emails from Microsoft Outlook as well.

Can you close Outlook with scheduled email?

Delay the delivery of a messageWhile composing a message, select the More options arrow from the Tags group in the Ribbon. Under Delivery options, select the Do not deliver before check box, and then click the delivery date and time you want. Click Close. When you're done composing your email message, select Send.

How do I create and send an e-mail using R?

allows you to create and send e-mails using R. It works similarly to the Shiny package, but instead of writing R code to create an interactive application, you write R code to create an HTML e-mail that can be rendered across a wide variety of e-mail providers. Once you’ve programmatically created an HTML e-mail,

How to send/receive COM objects from within R?

You can use RDCOMClient package to access to COM objects from within R. You can easily access the Application Object (Outlook) and configure it. Here a simple example of sending an email: Of course, this assumes that you have already install outlook and configure it to send/receive your emails.

How to send/receive emails using rdcomclient in R?

You can use RDCOMClient package to access to COM objects from within R. You can easily access to Application Object (Outlook) and configure it to send your emails. Here a simple example that show how to send and email: Of course, this assumes that you have already install outlook and configure it to send/receive your emails.

How do I send an email in MS Outlook?

But the most interesting one for me is to send email. To do that, start by creating an email object using the create_mail () method of your ms_outlook object, such as: When you run code creating an email object, a draft email should be saved in your Outlook Drafts folder.


Video Answer


2 Answers

You can use RDCOMClient package to access to COM objects from within R. You can easily access the Application Object (Outlook) and configure it. Here a simple example of sending an email:

library(RDCOMClient) ## init com api OutApp <- COMCreate("Outlook.Application") ## create an email  outMail = OutApp$CreateItem(0) ## configure  email parameter  outMail[["To"]] = "[email protected]" outMail[["subject"]] = "some subject" outMail[["body"]] = "some body" ## send it                      outMail$Send() 

Of course, this assumes that you have already install outlook and configure it to send/receive your emails. Adding attachment is quite simple also:

outMail[["Attachments"]]$Add(path_to_attch_file) 

sending on behalf of secondary mailbox:

outMail[["SentOnBehalfOfName"]] = "[email protected]" 
like image 94
agstudy Avatar answered Sep 19 '22 12:09

agstudy


It is possible to send emails in R via Outlook. sendmailR works for me on Windows 7 and Outlook 2010. I referenced http://cran.es.r-project.org/web/packages/sendmailR/sendmailR.pdf

smtpServer= info for Outlook 2010 is in File -> Account Settings -> Account Settings -> double click your account -> text in "Server" box

library(sendmailR)  #set working directory setwd("C:/workingdirectorypath")  #####send plain email  from <- "[email protected]" to <- "[email protected]" subject <- "Email Subject" body <- "Email body."                      mailControl=list(smtpServer="serverinfo")  sendmail(from=from,to=to,subject=subject,msg=body,control=mailControl)  #####send same email with attachment  #needs full path if not in working directory attachmentPath <- "subfolder/log.txt"  #same as attachmentPath if using working directory attachmentName <- "log.txt"  #key part for attachments, put the body and the mime_part in a list for msg attachmentObject <- mime_part(x=attachmentPath,name=attachmentName) bodyWithAttachment <- list(body,attachmentObject)  sendmail(from=from,to=to,subject=subject,msg=bodyWithAttachment,control=mailControl) 

In addition, multiple files can be sent by adding another mime_part to the msg list as follows (I also condensed it):

attachmentObject <- mime_part(x="subfolder/log.txt",name="log.txt") attachmentObject2 <- mime_part(x="subfolder/log2.txt",name="log2.txt") bodyWithAttachment <- list(body,attachmentObject,attachmentObject2) 
like image 35
ARobertson Avatar answered Sep 21 '22 12:09

ARobertson