Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove grey border from Blastula emails in R

By default, Blastula encloses RMarkdown emails with a gray border. This looks wrong on Gmail, as Gmail already adds a gray border to emails, boxing all your rmarkdown mails with a white box inside a gray box, inside a another white box inside yer another gray box.

enter image description here

The code I used to produce this email is as follows:

informe_html <- readr::read_file("html_email.html")
  email <- compose_email(body = md(informe_html))

My html file has no borders at all, just the dark grey background over a white background. The remaining light gray, white and light gray borders are added by Blastula.

like image 235
Bastián Olea Herrera Avatar asked Oct 21 '25 08:10

Bastián Olea Herrera


1 Answers

The email object produced from compose_email() contains HTML, so you can use string manipulation to change the appearance of the email. When you inspect the HTML code, the grey looks like it is coming from the <body> tag, which has the style attribute: background-color:#f6f6f6. Removing this tag should remove the grey border around the message.

blastula_message objects seem to have two versions of the HTML for the message:

  • html_str: The raw HTML stored as a character string.
  • html_html: The HTML stored as a html object.

The first is what actually gets sent when you use smtp_send() and the second seems to be what you see when you preview the message via print(email). To be safe you can remove the background-color attribute from both:

email$html_str <- sub(
  x = email$html_str,
  pattern = "background-color:#f6f6f6(;)",
  replacement = "")

email$html_html <- sub(
  x = email$html_html,
  pattern = "background-color:#f6f6f6(;)",
  replacement = "")

The (;) in the pattern is in case background-color isn't the only style attribute for <body>.

When you preview email the grey border should now be gone as the background of the mail will now be transparent.

like image 185
Dan Kennedy Avatar answered Oct 23 '25 22:10

Dan Kennedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!