FinProg
FinProg

Reputation: 155

Sending email attachment in R via Outlook

I need to send an email attachment in R via Microsoft Outlook. All of the code on this page works except for the line of code that sends an email attachment. Sending email in R via outlook

The line of code that does NOT work for me is:

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

Does anyone have any advice or suggestions? Thank you in advance for your help!

I'm sorry; I just realized that it's difficult to read my error messages and block of code, in my replies to your comments.

The following is the error message I got:

checkErrorInfo> 80020009 
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.

This is the entire block of code I ran:

require(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
outMail <- OutApp$CreateItem(0)
outMail[["bcc"]] <- "[email protected]"
outMail[["subject"]] <- "TEST"
outMail[["body"]] <- "This is a TEST"
outMail[["Attachments"]]$Add("A:/Automate_Emails/Test_Attachment.pdf")
outMail$Send()

Please note that I only got the error message when I ran the 2nd to last line of code, which is:

outMail[["Attachments"]]$Add("A:/Automate_Emails/Test_Attachment.pdf")

Thank you so much for your help! Best Regards.

Upvotes: 3

Views: 2217

Answers (1)

mannym
mannym

Reputation: 335

Your issue lies in the fact that you have not escape the escape when adding the attachment

You have the below

 outMail[["Attachments"]]$Add("A:/Automate_Emails/Test_Attachment.pdf")

You it should look like this

 outMail[["Attachments"]]$Add("A:\\Automate_Emails\\Test_Attachment.pdf")

Upvotes: 3

Related Questions