dmb
dmb

Reputation: 567

Download and save Outlook message attachment with R

Given that I have a .msg file saved to a directory on my C: drive, wondering if someone has a developed a solution in R to download and save the Outlook message attachment in this .msg file? I have discovered there is a solution for this in C# posted by Microsoft at https://msdn.microsoft.com/en-us/library/ms268754.aspx

Thank you for your help!

Upvotes: 1

Views: 2090

Answers (1)

lukeA
lukeA

Reputation: 54247

This does the trick:

# devtools::install_github("hrbrmstr/msgxtractr")
library(msgxtractr)
fn <- "~/mydir/mymsg.msg"
msg <- read_msg(fn)
invisible(lapply(msg$attachments, function(a) 
  writeBin(a$content, file.path(dirname(fn), a$filename)) 
))

It puts the message content in a list (see str(msg)), and saves the attachments under their original filenames.

PS: As you are refering to attachments, I assume there is no need to download anything. (It's in the nature of an attachment that it comes with the message, in contrast to example just a link to a PDF.)

Upvotes: 1

Related Questions