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 firstname.lastname@example.org
2 Larry Barrows email@example.com
sub <- "Can I borrow some flour"
email_sender <- 'Your Neighbor <firstname.lastname@example.org>'
body <- "Dear %s,
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>)?
email_dat <- addressees %>%
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)
emails <- email_dat %>%
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 %>%
paste('data/',gsub("\\s+", "_", sub), "_trial-sent-emails.rds", sep = ""))