blastula R Package

repository·master·Indexed 20 days ago

https://github.com/rstudio/blastula

An R package for producing and sending responsive, well-formatted HTML emails. It supports Markdown, block-based components, and images. Key functionality includes composing emails via compose_email(), sending via SMTP using smtp_send(), and integrating email reports with Posit Connect using render_connect_email() and attach_connect_email().

Tokens
764
Snippets
4
Records
5
Agent score
19%

What's inside blastula

  1. Send email reports through Posit Connect

    master
    For workflows involving R Markdown on Posit Connect, blastula supports a main report + email report pattern. This involves setting the output type to blastula::blastula_email in the email report and using render_connect_email() and attach_connect_email() within your main report to automate the process.
  2. Compose an HTML email message

    master

    Use compose_email() to create an email object. The message consists of three main content areas: body, header, and footer. You can pass Markdown text to these areas using the md() function. To include images, transform an on-disk file into an HTML string using add_image().

    # 1. Prepare content components
    date_time <- add_readable_time()
    
    img_file_path <- system.file("img", "pexels-photo-267151.jpeg", package = "blastula")
    img_string <- add_image(file = img_file_path)
    
    # 2. Compose the email
    email <- compose_email(
        body = md(glue::glue(
    "Hello,
    
    This is a *great* picture I found when looking
    for sun + cloud photos:
    
    {img_string}
    ")),
        footer = md(glue::glue("Email sent on {date_time}."))
      )
    
    # 3. Preview the email in the RStudio Viewer
    email
  3. Send an email via SMTP

    master

    To send an email through an SMTP server, use the smtp_send() function. It is recommended to store your SMTP credentials in a file using create_smtp_creds_file() and then reference that file using the creds_file() helper.

    # Sending email by SMTP using a credentials file
    email |> 
      smtp_send(
        to = "jane_doe@example.com",
        from = "joe_public@example.net",
        subject = "Testing the `smtp_send()` function",
        credentials = creds_file("email_creds")
      )
  4. Install the blastula package

    master

    You can install the stable version of blastula from CRAN or the development version from GitHub using devtools.

    # Install from CRAN
    install.packages("blastula")
    
    # Install development version from GitHub
    devtools::install_github("rstudio/blastula")
  5. Preview an email message

    master

    After composing an email object with compose_email(), you can preview its formatting by simply calling the object in your R console. This will display the rendered HTML in the RStudio Viewer.

    # Assuming 'email' is your composed email object
    email