1

I'm trying to create emails with R using the package RDCOMClient. The emails basically consist of HTML text encoded in UTF-8 (and also some images). The problem that I'm having is that while the HTML encodes all the special characters I need perfectly, after I save the email as .msg file and open it with Outlook, the special characters don't appear correctly anymore. So something must be going wrong when I use the SaveAs functionality of RDCOMClient.

Here is a minimal example of my code:

library(RDCOMClient)
library(textutils)
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = 'myemail@test.com'
outMail[["subject"]] = 'Dummy subject'
outMail[["HTMLBody"]] <- HTMLdecode('&nbsp;<b>Tout est prêt de votre côté? Faisons une vérification</b> </br>')
outMail$SaveAs(print(paste0(getwd(), '/test', ".msg",collapse="")))

The body of the output email then looks as follows:

 Tout est pr攼㹡t de votre c昼㸴t攼㸹? Faisons une v攼㸹rification

I've tried A LOT of different approaches involving encoding. In my actual case, I'm reading in the text for the body of the email from a csv file that is UTF-8 encoded. I've tried playing around with the enc2native() function, as well as with setting a different encoding (using withr and set.encoding etc.). Moreover, I also tried it out on a computer that had French language settings as well as on a Mac, all with no luck...

I realized that when I try it with just the raw sentence without any HMTL code it works perfectly fine:

HTMLdecode('Tout est prêt de votre côté? Faisons une vérification')

I've been trying to solve this for the past 2 days and I'm really close to just moving everything to Python because I'm so frustrated with R at the moment, however I'm not sure if I'd have exactly the same problem on Python as well.

Does anyone have any idea of how to solve that?

Thanks a lot in advance!

Tom Bombadil
  • 183
  • 4

1 Answers1

-1

I found it! You have to save your program with encoding" latin9".