0

I have created the following code to send an email with from address set with UTF-8 format. I know that msmtp has IDN support, but when i run this program, i get an error message that character \xe2\x82\xac (aka '€') is invalid.

msmtp: envelope from address relu\u20ac@4p\u20ac.com not accepted by the server
msmtp: server message: 555 5.5.2 Syntax error. p83sm6227819wma.18 - gsmtp
msmtp: could not send mail (account default from /usr/local/etc/msmtprc)

This is the code:

#include <stdio.h>
int main(){
    char* sender = "relu\xe2\x82\xac@4p\xe2\x82\xac.com";
    char cmd[100];
    sprintf(cmd, "echo \"bla\" | msmtp -f %s example@domain.com", sender);
    system(cmd);    
    return 0;
}

1 Answers1

0

It seems like your environment doesn't understand that you're giving it complex characters. Make sure you're parsing the chars as unicode. If you try parsing a unicode value as ascii, you'll get some pretty weird results.

You may want to look into using wchar_t instead of char*.

nmg49
  • 1,356
  • 1
  • 11
  • 28
  • Actually, when i use printf("%s\n", sender); it outputs the address to the console correctly (it displays the 'euro' character). – Relu Dragan Jul 15 '16 at 14:56