0

I'm trying to send an Outlook mail thru R by using RDCOMClient and trying to attach an Excel file in it but getting an error.

Below is my script:

library(RDCOMClient)
## init com API
OutApp <- COMCreate("Outlook.Application")
## Create an email 
outMail = OutApp$CreateItem(0)
## Configure email parameter 
outMail[["To"]] = "ashishpatil@orientindia.net"
outMail[["cc"]] = "atulkadam@orientindia.net"
outMail[["subject"]] = paste0("RE: Update your Todays date",format(Sys.Date(),"%d-%m-%y"),"Timesheet.")
outMail[["body"]] = "Dear Sir/Madam,
       Please find below the CMS Application - Total Count of Records Uploaded Status:"
outMail[["Attachments"]]$Add("C:/Users/atulkadam/OneDrive - Orient Technologies Pvt. Ltd/Atul/Time Sheet/atul kadam",Sys.Date(),".xlsx")
## Send it                     
outMail$Send()

when I run the Attachments code It shows me the below error.

Error in.COM(x, name, ...) : 
 [Error code][1] Can't attach the RDCOMServer package needed to create a generic COM object
Phil
  • 7,287
  • 3
  • 36
  • 66
  • even tried in another way also: https://stackoverflow.com/questions/41282094/how-to-show-an-excel-worksheet-in-outlook-body-by-r but it also shows me an error. please help me in this. – Atul Kadam Aug 18 '23 at 10:46

1 Answers1

0

The below Code works for me;

library(RDCOMClient)
## init com API
OutApp <- COMCreate("Outlook.Application")
## Create an email 
outMail = OutApp$CreateItem(0)
## Configure email parameter 
path_to_attachment <- paste0("C:/Users/atulkadam/OneDrive - Orient Technologies Pvt. Ltd/Atul/Time Sheet/atul kadam")

outMail[["To"]] = "atulkadam@orientindia.net"
outMail[["cc"]] = "ashishpatil@orientindia.net"
outMail[["subject"]] = paste0("RE: Update your Todays date",format(Sys.Date(),"%d-%m-%y"),"Timesheet.")

outMail[["body"]] = "Dear Sir/Madam,
       Please find below the CMS Application - Total Count of Records Uploaded Status:"
outMail[["Attachments"]]$Add(paste0(path_to_attachment,format(Sys.Date(),"%d-%m-%Y"),".xlsx"))
## Send it                     
outMail$Send()
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 20 '23 at 12:14