I receive daily emails where there is an attachment containing 1 zip file containing 1 csv file.
In the body of my email, there is an image that is being recognized
email$Attachments(1)$SaveAsFile(attachment_file)
will save the first attachment to the file path defined by attachment_file
, according to some unknown ordering. If you're sure there'll only be one file with a ".zip" extension then you can use the FileName
method to check that the name of the attachment contains ".zip":
attachment_file <- tempfile()
for (i in 1:email$Attachments()$Count()) {
attachment <- email$Attachments(i)
if (grepl(".zip", attachment$FileName(), ignore.case = TRUE)) {
attachment$SaveAsFile(attachment_file)
}
}