rayfinkle
rayfinkle

Reputation: 85

add (png) image inline in an email using R / sendmailR

I am attempting to send an HTML email with inline images. The text below is abridged, but works fine.

theString=paste0(
   '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
   Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
   <title>HTML demo</title>
   <style type="text/css">
   </style>
   </head>
   <body>
   <h1>Notes</h1>
   '</body>
   </html>'

msg = mime_part(theString)

## Override content type.
msg[["headers"]][["Content-Type"]] = "text/html"

sendmail(from = "[email protected]",
         to = c("[email protected]"),
         bcc=bccList,
         subject = theSubject,
         msg = msg,
         html = TRUE,
         smtp = list(
            host.name = "aspmx.l.google.com", 
            port = 25, 
            user.name = "***", 
            passwd = "***", 
            ssl = TRUE
         ),
         authenticate = TRUE,
         send = TRUE
         )

I'd like to be able to send a *.png image inline (so, perhaps after the "Notes" header in the HTML).

I have a set of *png files in my home directory, but can't figure out how to get the image attached or inline.

Thank you!

Upvotes: 3

Views: 1044

Answers (1)

torenunez
torenunez

Reputation: 130

This worked for me as long as you also add the source .png file as an attachment using mime_part.

Upvotes: 1

Related Questions