How to attach two files when sending message to SMTP Server (emayili+Outlook)

Viewed 198

I have been setting the emayili package to send email with two attached files from my Outlook account, but so far I have been unable to do it.

The code is as following (with emails and passwords replaced with 'aaa' and 'bbb' for privacy/security):

email <- envelope(
  from = "aaa@domain.com",
  to = "bbb@domain.com",
  subject = subject,
  html = body) %>%
  attachment('filename1.xlsx') %>%
  attachment('filename2.xlsx')

smtp <- server(host = "smtp.mailtrap.io",
        port = 587,
        username = "********",
        password = "*********")

smtp(email, verbose = TRUE)

When I run the code, I get the following result:

> smtp(email, verbose = TRUE)
Sending email to smtp.office365.com:587/.
Error: Request failed after 5 attempts
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning messages:
1: In smtp(email, verbose = TUE) :
 ​ restarting interrupted promise evaluation
2: In f(...) : restarting interrupted promise evaluation
3: In f(...) : restarting interrupted promise evaluation
4: In f(...) : restarting interrupted promise evaluation
5: In f(...) : restarting interrupted promise evaluation

Any idea what is going wrong?

1 Answers

Also try to use library(Microsoft365R)


 outl <- get_personal_outlook()

 #your code
 # using emayili to create an email with attachments
 ey_email <- emayili::envelope(
 text="Hello from emayili",
 to="user@example.com",
 subject="example emayili email") %>%
 emayili::attachment("mydocument.docx") %>%
 emayili::attachment("mydata.xlsx")
 outl$create_email(ey_email)
 #your code

Full manual you can find there

Related