mailR
mailR copied to clipboard
Chinese incorrect codes show in body of email(mailR) when it shows correct just run it with html
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
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)
`
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?
@rpremraj yes,i added 'encoding='utf-8'' as it in your example,but not work for me ......
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)
I also encountered the same problem, is there any solution? @rpremraj
It seems that problem with encoding of html-file via Rmail has dissapeared in R 3.4.3
I encountered the same problem,too. Is there any solution? @rpremraj
Same problem for me. There is still no solution to this problem?
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)