luka12341
luka12341

Reputation: 1

Save email to a local folder in R

I have a quite simple question. I am using sendmailR to send automatic emails, however i would like to make automatic archive of what has been sent out on local folder for the purpose of transparency.

does anyone know how to do this?

Upvotes: 0

Views: 161

Answers (1)

Waldi
Waldi

Reputation: 41220

You could create a list with the arguments you already use for sendmail and save it as RDS each time you send a new mail:

from <- "[email protected]"
to <- "[email protected]" 
subject <- "Hello from R" 
msg <- "my email" 

mail <- list(from = from, to = to, subject = subject, msg = msg)
sendmail(from, to, subject, msg)

if (file.exists('mailarchive.RDS')) {
  maillist <- readRDS('mailarchive.RDS')
} else {
  maillist <- list()
}

maillist[[length(maillist)+1]] <- mail
saveRDS(maillist,'mailarchive.RDS')

maillist

[[1]]
[[1]]$from
[1] "[email protected]"

[[1]]$to
[1] "[email protected]"

[[1]]$subject
[1] "Hello from R"

[[1]]$msg
[1] "my first email"
...

Upvotes: 0

Related Questions