Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easily send great-looking HTML email messages from R

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

rstudio/blastula

Repository files navigation


CRAN statusLicense: MITR build statusCoverage status

The project has reached a stable, usable state and is being actively developed.Monthly DownloadsTotal Downloads

Contributor Covenant

Theblastula package makes it easy to produce and send HTML email fromR. The message can have three content areas (the body, the header, and the footer) and we can insertMarkdown 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 theadd_readable_time() function, and, transform an image on disk to an HTML string object (img_string).

# Get a nicely formatted date/time stringdate_time<- add_readable_time()# Create an image string using an on-disk# image fileimg_file_path<-  system.file("img","pexels-photo-267151.jpeg",package="blastula"  )img_string<- add_image(file=img_file_path)

Now we use thecompose_email() function to compose the email. There are three main arguments here:body,header, andfooter. You can supplyMarkdown 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 withglue::glue() and, since we have Markdown and HTML fragments, we need to use themd() function.

email<-  compose_email(body= md(glue::glue("Hello,This is a *great* picture I found when lookingfor sun + cloud photos:{img_string}")),footer= md(glue::glue("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 emailemail

Sending an Email Message via SMTP

We can store SMTP email credentials in a file using thecreate_smtp_creds_file() function. There are also other ways to set up SMTP access credentials (like using system-wide key-value store through thecreate_smtp_creds_key() function).

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

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

Sending Email Messages through Posit Connect

We can also send email based onR Markdown files throughPosit Connect. Theprepare_rsc_example_files() function provides .Rmd files that facilitate a main report + email report workflow. The key components are theblastula::blastula_email output type for the email report, and the use ofrender_connect_email() andattach_connect_email() in the main report.

Installation

Want to try this out? Theblastula package is available onCRAN:

install.packages("blastula")

You can also install the development version ofblastula fromGitHub:

devtools::install_github("rstudio/blastula")

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

Code of Conduct

Please note that therstudio/blastula project is released with acontributor code of conduct.
By participating in this project you agree to abide by its terms.

📄 License

blastula is licensed under the MIT license. See theLICENSE.md file for more details.

© Posit Software, PBC.

🏛️ Governance

This project is primarily maintained byRichard Iannone. Should there also be other authors, they might occasionally assist with some of these duties.

About

Easily send great-looking HTML email messages from R

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Contributors21


[8]ページ先頭

©2009-2025 Movatter.jp