6

I need your help in order to send email message that includes text in Greek, from within R, using the function sendmail {sendmailR}.

I tried using the function iconv, like that but it didn't work

subject <- iconv("text in greek", to = "CP1253")
sendmail(from, to, subject, msg, control=list(smtpServer="blabla"))

The mail arrives immediately but the greek characters are unreadable. Any ideas?

EDIT

Another question that came up: The second argument to accepts one recipient. What if want to send it to more than one? (I think 'll try sapply ing the sendmail function to a vector of recipients) - Ok, that worked. However, I'm not completely satisfied because each one of the recipients has no way to know who else has received the message.

gd047
  • 29,749
  • 18
  • 107
  • 146

1 Answers1

4

Mail client won't be able to understand any encoding without Content-Type: charset=..., so you must add it:

msg<-iconv("text in greek", to = "utf8");
sendmail(from, to, subject, msg, 
control=list(smtpServer="blabla"),
headers=list("Content-Type"="text/plain; charset=UTF-8; format=flowed")
);

that is for UTF8 (which I believe should be used), for CP1253:

msg<-iconv("text in greek", to = "CP1253");
sendmail(from, to, subject, msg, 
control=list(smtpServer="blabla"),
headers=list("Content-Type"="text/plain; charset=CP1253; format=flowed")
);

multisend by hidden copies can also be done with header magick, still I think sapply loop is a better idea -- then the user will see that the mail was send directly to her/himself.

mbq
  • 18,510
  • 6
  • 49
  • 72
  • Thank you. First of all, if there is a better way for sending mail, I'm ready to abandon sendmailR. What do you mean by 'invoke sendmail by system'. Note that I'm using windows. – gd047 Aug 20 '10 at 09:02
  • Sorry, I have underestimated this package; try this. – mbq Aug 20 '10 at 09:09
  • Windows... ok, that is a problem; still there is fake sendmail for Windows http://glob.com.au/sendmail/ . Nevertheless the lowest level mail sending goes by composing message manually (you can see how the e-mails really look by pressing `show message source` or similar in your mail client) and just piping it to sendmail. – mbq Aug 20 '10 at 09:13
  • Of course this latter comment is in case if sendmailR fails; I have just tested my method and it appears to work. – mbq Aug 20 '10 at 09:21
  • Thank you very much. You were right! It worked only for utf8. How did you know how to define `Content-Type` ? – gd047 Aug 20 '10 at 10:07
  • 1
    Mainly by reading sources of messages produced by Thunderbird; still this is a part of MIME standard http://en.wikipedia.org/wiki/MIME#Content-Type – mbq Aug 20 '10 at 10:38
  • Could you possibly also tell me what I should change/add in order to send a message that includes an attachment? – gd047 Aug 25 '10 at 12:22
  • @gd047 -- can you post new question about attachments? This seems overloaded. – mbq Aug 25 '10 at 18:48