Continuing the discussion from Embedding hyperlinks in the text of a gmailr message:
Thanks so much! I did see this vignette once before, but your pointing me back to it definitely helped me find my way to my solution. I also think I misspecified my problem in the original post. I was having trouble getting the links embedded, and that vignette helped to accomplish that.
Additionnally, I was also having trouble using map
or one of its variants to change the body of my message from text to html after creating the mime message. Eventually, I figured out I could just change the attribute within the pmap
function near the end of Jenny Bryan's tutorial. I put an example (with fake names, emails, website, and message) below that is illustrates how I adapted adopted Jenny Bryan’s tutorial for my context. All of the steps are the same except for the bit near the end (commented).
> addressees %>% select(first_name, last_name, email)
# A tibble: 2 x 3
first_name last_name email
<chr> <chr> <chr>
1 Elois Barrows ebarrows@gmail.com
2 Larry Barrows lbarrows@gmail.com
sub <- "Can I borrow some flour"
email_sender <- 'Your Neighbor <neighor@gmail.com>'
body <- "Dear %s,
<br>
<br>
Would you mind if I stopped by after work to borrow some of that flour you bought from this (<a href='http://www.buygreatflourhere.com/'>online vendor</a>)?
<br>
<br>
Best, <br>
Your Neighbor
"
email_dat <- addressees %>%
mutate(
To = sprintf('%s %s <%s>', first_name, last_name, email),
From = email_sender,
Subject = sub,
body = sprintf(body, first_name, sub)
) %>%
select(To, From, Subject, body)
write_csv(edat, "data/trial-composed-emails.csv")
emails <- email_dat %>%
pmap(., mime,
attr = list(content_type = "text/html")) #this line right here converted the body of the email from "text/plain" to "text/html"
str(emails, max.level = 2, list.len = 2)
safe_send_message <- safely(send_message)
sent_mail <- emails %>%
map(safe_send_message)
saveRDS(sent_mail,
paste('data/',gsub("\\s+", "_", sub), "_trial-sent-emails.rds", sep = ""))