Hello everyone,
This is my first post and I am very new to R so please excuse any inconsistencies in my explanations.
Here's the scenario:
I am trying to download a .txt attachment from Outlook that gets automatically emailed to me every day, convert it to .xlsx, name it, and replace/overwrite the file from the day before.
I cannot modify the subject line or the file name, so I am hoping to this based on specific text from the email.
Below is my best attempt at it. When I go to run it, RStudio experiences a fatal error and crashes...
devtools::install_github("omegahat/RDCOMclient")
require(RDCOMClient)
require(readtext)
require(rio)
require(readr)
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpmail:textdescription like 'Student Demographics - Dashboard'"
)
Sys.sleep(15)
results <- search$Results()
for (i in 1:results$Count()) {
if(as.Date(floor(results$Item(i)$ReceivedTime()), origin = "1899-12-30") == Sys.Date()) {
email <- results$Item(i)
}
}
attachment_file <- "G:/My Drive/Dashboards.txt"
email$Attachments(1)$SaveAsFile(attachment_file)
I am using version 4.1.1 in my attempt.
Any help you can provide is greatly appreciated. Thank you for your time!