Extracting Zip+CSV file from attachment w/ Image in Body of Email

后端 未结 1 1352
情歌与酒
情歌与酒 2020-12-10 00:12

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

相关标签:
1条回答
  • 2020-12-10 00:40

    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)
        }
    }
    
    0 讨论(0)
提交回复
热议问题