Recently I used another AWS service to take on repetitive work. The service is AWS SES service.

I wanted to send out a email using text from an early Church Father, so that a group of recepients could recieve a quote from St. Mark the Ascetic every day. I built this using AWS simple email service and will post sometime sepeartely about the set up process.

The text of St. Mark the ascetic is found on my other site: http://orthodoxriver.org/

library(aws.ses)
library(dplyr)
library(stringr)

download.file('http://paintedriver.us/static/st_mark.RDS', destfile = "st_mark.RDS")
sm <- readRDS("st_mark.RDS")
cat(format(Sys.Date(), "%m/%d/%Y"))

# aws login you will need to set this up on your local machine
aws.signature::use_credentials()

# the data is a smaill quote for each day
td = paste0(Sys.Date())
sm.tmp <- filter(sm, date == td)

text <- paste0("St. Mark the Ascetic: ", "\n", sm.tmp$sm)
# get the first six words from the text for the subject -
subject = word(text, 6, 14, sep=" ")
####################################################
# add receiptients to the vector ###################
####################################################
send_to = c("friends@gmail.com", "more@gmail.com")
send_from = "info@paintedriver.us"

You can add up to 50 emails in a vector and then loop through them to send them out. You also need to go through the authentication process with aws.ses to create a verified sender email. This email allows you to send emails without problems.

Also, at first I used a for loop, but the aws.ses library did not like it and it continously sent strange errors. I found that with using lapply it worked perfectly. Here is the code to use lapply.

# send the file to ses
lapply(send_to, function(x){
  send_email(text, subject = subject, from = send_from,
             to = x)
})