Giter VIP home page Giter VIP logo

blastula's Introduction

blastula

CRAN status Travis-CI Build Status Codecov test coverage

Overview

The blastula package makes it easy to produce and send HTML email from R. The message can have three content areas (the body, the header, and the footer) and we can insert Markdown text, block-based components, and even HTML fragments. The underlying HTML/CSS is meant to display properly across a wide range of email clients and webmail services. The resulting email message is responsive so it’ll look great on both large displays and mobile devices.

Composing an Email Message

When you compose an email, you can use objects from the global workspace and work them into the message content. Let’s create a nicely formatted date/time string (date_time) with the add_readable_time() function, and, transform an image on disk to an HTML string object (img_string).

# Get a nicely formatted date/time string
date_time <- add_readable_time()

# Create an image string using an on-disk
# image file
img_file_path <-
  system.file(
    "img", "pexels-photo-267151.jpeg",
    package = "blastula"
  )

img_string <- add_image(file = img_file_path)

Now we use the compose_email() function to compose the email. There are three main arguments here: body, header, and footer. You can supply Markdown text to any of these content areas to get rendered HTML.

In the example code below, the strings that are part of the email body and the email footer are combined with c() and, since we have Markdown and HTML fragments, we need to use the md() function.

email <-
  compose_email(
    body = md(
      c(
"Hello,

This is a *great* picture I found when looking
for sun + cloud photos:
",
img_string
      )
    ),
footer = md(
  c(
    "Email sent on ", date_time, "."
  )
)
  )

After creating the email message, we can look at it to ensure that the formatting is as expected. Simply call the object itself and it will be displayed in the Viewer.

# Preview the email
email

Sending an Email Message via SMTP

We can store SMTP email credentials in a file using the create_smtp_creds_file() function. This will create a hidden credentials file in the working directory. We can also set SMTP access credentials in the system-wide key-value store through the create_smtp_creds_key() function.

Having generated a credentials file, we can use the smtp_send() function (along with the creds_file() credentials helper function) to send the email through an SMTP server.

# Sending email by SMTP using a credentials file
email %>%
  smtp_send(
    to = "[email protected]",
    from = "[email protected]",
    subject = "Testing the `smtp_send()` function",
    credentials = creds_file("email_creds")
  )

Installation

The blastula package can be installed from CRAN with install.packages().

install.packages("blastula")

You can install the in-development version of blastula from GitHub using the devtools package.

install.packages("devtools")
devtools::install_github("rich-iannone/blastula")

If you encounter a bug, have usage questions, or want to share ideas to make this package better, feel free to file an issue.

Code of Conduct

Please note that the blastula project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

MIT © Richard Iannone

blastula's People

Contributors

alternikaner avatar emilyriederer avatar fmichonneau avatar jcheng5 avatar jonmcalder avatar merlinoa avatar rich-iannone avatar salim-b avatar vfulco avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.