3

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"]] <- "someone@someemail.com"
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.

mannym
  • 325
  • 1
  • 16
FinProg
  • 155
  • 1
  • 7
  • 3
    What is the error message? – tigerloveslobsters Mar 14 '18 at 18:11
  • 1
    can you put the actual code you have tried here? – pyll Mar 14 '18 at 18:11
  • Specifically, include entire code block with all `library` lines. – Parfait Mar 14 '18 at 18:24
  • Sorry, for not including my error message and entire code block with library line. My error message is: checkErrorInfo> 80020009 No support for InterfaceSupportsErrorInfo checkErrorInfo -2147352567 Error: Exception occurred. – FinProg Mar 14 '18 at 22:52
  • The entire block of code that I tried is: require(RDCOMClient) OutApp <- COMCreate("Outlook.Application") outMail <- OutApp$CreateItem(0) outMail[["bcc"]] <- "someone@someemail.com" outMail[["subject"]] <- "TEST" outMail[["body"]] <- "This is a TEST" outMail[["Attachments"]]$Add("Z:/AutomateEmails/Test_Attachment.pdf") outMail$Send() All of the code worked except for: outMail[["Attachments"]]$Add("Z:/AutomateEmails/Test_Attachment.pdf") Thank you so much for your help! – FinProg Mar 14 '18 at 22:58

1 Answers1

3

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")
mannym
  • 325
  • 1
  • 16