## ----------------------------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----------------------------------------------------------------------------- library(gmailr) ## ----------------------------------------------------------------------------- text_msg <- gm_mime() |> gm_to("james.f.hester@gmail.com") |> gm_from("me@somewhere.com") |> gm_text_body("Gmailr is a very handy package!") ## ----------------------------------------------------------------------------- strwrap(as.character(text_msg)) ## ----------------------------------------------------------------------------- html_msg <- gm_mime() |> gm_to("james.f.hester@gmail.com") |> gm_from("me@somewhere.com") |> gm_html_body("Gmailr is a very handy package!") ## ----------------------------------------------------------------------------- write.csv(file = "iris.csv", iris) msg <- html_msg |> gm_subject("Here are some flowers") |> gm_attach_file("iris.csv") ## ----------------------------------------------------------------------------- msg <- html_msg |> gm_attach_part(part = charToRaw("attach me!"), name = "please") ## ----------------------------------------------------------------------------- # First create a plot to send, and save it to mtcars.png mtcars$gear <- as.factor(mtcars$gear) png("mtcars.png", width = 400, height = 400, pointsize = 12) with( mtcars, plot(hp, mpg, col = as.factor(gear), pch = 19, xlab = "Horsepower", ylab = "Miles / gallon" ) ) legend("topright", title = "# gears", pch = 19, col = seq_along(levels(mtcars$gear)), legend = levels(mtcars$gear) ) dev.off() # Next create an HTML email that references the plot as 'foobar' email <- gm_mime() |> gm_to("someaddress@somewhere.com") |> gm_from("someaddress@somewhere.com") |> gm_subject("Cars report") |> gm_html_body( '