mailR icon indicating copy to clipboard operation
mailR copied to clipboard

Chinese incorrect codes show in body of email(mailR) when it shows correct just run it with html

Open Chelsiechj opened this issue 8 years ago • 9 comments

I tried to send an email(mailR) which body embeded from rmarkdown html report,but show Chinese incorrect codes .Though it has no problem when i just run in .Rmd file. Can anybody give advides?Thanks image

Chelsiechj avatar Jun 05 '16 01:06 Chelsiechj

Did you select the right encoding when sending the email?

See for example:

send.mail(from = "Sender Name <[email protected]>",
                   to = "[email protected]",
                   subject = "A quote from Gandhi",
                   body = "In Hindi :  थोडा सा अभ्यास बहुत सारे उपदेशों से बेहतर है।
                   English translation: An ounce of practice is worth more than tons of preaching.",
                   encoding = "utf-8",
                   smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "gmail_username", passwd = "password", ssl = T),
               authenticate = TRUE,
                   send = TRUE)
`

rpremraj avatar Jul 05 '16 19:07 rpremraj

I am having the similar problem. Trying to send file generated from R Markdown v2 and it shows incorrect characters. The idea was to send markdown file from Rmd as text with output: github_document

Solution with encoding = "utf-8" didn't worked for me, but notepad++ shows utf-8 encoding and righ letters in generated file. So I tried reading file to variable and setting it as body.

fileContent <- readLines("aterkoppling.md", encoding = "UTF-8")

That's not working because (but RStudio shows right text):

Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.lang.NoSuchMethodException: No suitable method for the given parameters In addition: Warning message: In if (file.exists(body)) body <- readChar(body, file.info(body)$size) : the condition has length > 1 and only the first element will be used

Any ideas?

Muhomorik avatar Nov 28 '16 16:11 Muhomorik

@rpremraj yes,i added 'encoding='utf-8'' as it in your example,but not work for me ......

Chelsiechj avatar Dec 22 '16 07:12 Chelsiechj

I've met the same problem.

Here is my simple Rmd-file (also saved in RStudio with UTF-8 encoding))

**тест** (ukrainian)
**test** (english)

Here is R-script for creating html-document and sending it via mailR:

library(knitr)
library(mailR)

knit2html(input = "encoding_test.Rmd", encoding = "UTF-8")

send.mail(
  from = "[email protected]",
  to = "[email protected]",
  subject = "encoding test",
  html = TRUE,
  body = "encoding_test.html",
  encoding = "utf-8",
  smtp = list(
    host.name = "smtp.gmail.com",
    port = 465,
    user.name = "myUsername",
    passwd = "myPassword",
    ssl = TRUE
  ),
  authenticate = TRUE,
  send = TRUE
)

When you open an html-document in a browser the encoding is correct, notepad++ shows aslo UTF-8 encoding both for html- and md- documents. But in a body of an e-mail it shows like this:

тест (ukrainian) test (english)

woldemarg avatar Mar 18 '17 09:03 woldemarg

I also encountered the same problem, is there any solution? @rpremraj

roududu avatar Dec 08 '17 04:12 roududu

It seems that problem with encoding of html-file via Rmail has dissapeared in R 3.4.3

woldemarg avatar Jan 10 '18 19:01 woldemarg

I encountered the same problem,too. Is there any solution? @rpremraj

DawnYe avatar Jul 27 '18 09:07 DawnYe

Same problem for me. There is still no solution to this problem?

MislavSag avatar Dec 05 '18 10:12 MislavSag

I have found the solution:

sender <- "[email protected]"
recipients <- c("[email protected]")
send.mail(from = sender,
          to = recipients,
          subject = "R Markdown Report - rmarkdown",
          body = paste0(readLines("file.html", encoding = "UTF-8"), collapse = ""),
          encoding = "utf-8",
          html = TRUE,
          smtp = list(...),
          send = TRUE)

MislavSag avatar Dec 09 '18 15:12 MislavSag