1

I have an html file as an result of my Rmarkdown code. Now I need to send an email with this html file directly in the body of the email, and not in the attachement. I was trying the solution from this post: "send HTML email using R" post But it seems that it works only with html text and not html file. Here what I've tried to do:

library(sendmailR)
from<-"<sender@enterprise.lan>"
to<-c("<reciever@enterprise.com>")
message ="./TEST.html"
subject = "Test HTML"
msg <- mime_part(message)
msg[["headers"]][["Content-Type"]] <- "file/html"
sendmail(from, to, subject, msg = msg,control=list(smtpServer="localhost"),headers=list("Content-Type"="file/html; charset=UTF-8; format=flowed"))

This trial send me an email but with "TEST.html" file attached, and not in the body directly. Obviously I'm doing something wrong, I'm struggling with this task for days, can someone help me, please?

Community
  • 1
  • 1
user3825422
  • 143
  • 1
  • 2
  • 11
  • Answered here: http://stackoverflow.com/questions/21929170/email-dataframe-as-table-in-email-body-with-sendmailr – Benjamin Oct 27 '15 at 16:41
  • Thank you Benjamin. I've tried to use this solution, as I understand I need to include my html file into html code, here is how I tried to do it: ... ... I've also tried this: But every time the mail that I receive is empty. data="./TEST2.html" give also an empty mail – user3825422 Nov 03 '15 at 15:53

1 Answers1

1

Try the mailR package to easily send emails in HTML format as follows:

send.mail(from = "sender@gmail.com",
          to = c("recipient1@gmail.com", "recipient2@gmail.com"),
          subject = "Subject of the email",
          body = "<html>The apache logo - <img src=\"http://www.apache.org/images/asf_logo_wide.gif\"></html>", # can also point to local file (see next example)
          html = TRUE,
          smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)
Rahul Premraj
  • 1,595
  • 14
  • 13
  • Thank you for your answer, the problem is that i'm working out of Rstudio, and I can't install the library mailR. I receive this message: Warning message: package ‘mailR’ is not available (for R version 3.2.2) – user3825422 Nov 03 '15 at 15:35