Sending Email Attachement Through Outlook in R with RDCOMClient

末鹿安然 提交于 2019-12-03 13:18:51

Reverse the slashes and escape them.

The problem is that the path is being created in R, which prefers forward slashes (since the backslash is the escape character), but it's being interpreted by Outlook, which only takes backslashes.

For example, try adding an attachment to an Outlook email by pasting a path into the insert file dialogue, but change the backslashes to forward slashes. It doesn't accept it. And that's essentially what you're trying to do.

So reverse to make them backslashes, then add extra backslashes to each one to escape them. For example:

C:\\Users\\MyFiles\\Documents\\document.txt

R will strip out the escape characters and and pass a clean path to Outlook.

The answer that helped me was provided by David Arenburg in comments:

You need to specify a full path. Is L:/Document.csv a full path? Is L a local driver or you mapped a network driver? If later is the case you need to specify the actual network path.

Example: \\dfwcot\Home$\lando\bb8\2015-12-24 Daily Report.xlsx

The Add method of the Attachments class accepts four arguments. I'd suggest specifying them explicitly.

The source of the attachment can be a file (represented by the full file system path with a file name) or an Outlook item that constitutes the attachment. Make sure the file is accessible.

I was also facing the same issue of "Error: Exception occurred".

But, in my case i was missing the naming convention of file. So, make sure that the file name must not be separated by SPACE and use delimiter as "-".

You can use the gsub() function to change "/" to double back slashes "\" in your path

Use this:

outMail[["Attachments"]]$Add(gsub("/","\\" ,"L:/Document.csv", fixed = TRUE))

Martin

You need to do it like this

L:\\Document.csv

Worked for me. Use two backslashes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!