muquit / mailsend

A program to send mail via SMTP from command line
Other
297 stars 68 forks source link

SMTPUTF8 support #98

Open sanderjo opened 8 years ago

sanderjo commented 8 years ago

If a SMTP server says "SMTPUTF8" in the EHLO, the client can use UTF-8 in the MAIL FROM (see RFC6531) :

So:

[C] EHLO localhost
<bla>
[S] 250 SMTPUTF8

then

[C] MAIL FROM: <renéeee@example.com> SMTPUTF8
[S] 250 2.1.0 OK g3sm36498831wjb.47 - gsmtp

(Note the accent aigu in 'renéeee')

I put something together in smtp.c (for which I can send a pull request):

    if (check_server_cap("SMTPUTF8")) {
            (void) snprintf(buf,sizeof(buf)-1,"MAIL FROM: <%s> SMTPUTF8\r\n",from);
    } else {
            (void) snprintf(buf,sizeof(buf)-1,"MAIL FROM: <%s> \r\n",from);
    }

and that works:

[C] MAIL FROM: <renéeee@example.com> SMTPUTF8
[S] 250 2.1.0 OK bla.47 - gsmtp
[C] RCPT TO: <bla@gmail.com>
[S] 250 2.1.5 OK bla.47 - gsmtp
[C] DATA
[S] 354  Go ahead bla.47 - gsmtp
Subject: Helloooo
From: renéeee@example.com
Date: Mon, 30 May 2016 23:54:13 +0200
To: blabla@gmail.com
X-Mailer: @(#) mailsend v1.19 (Unix)
X-Copyright: BSD. It is illegal to use this software for Spamming

[C] this is my mail ...

[C] .
[S] 250 2.0.0 OK 1464645254 bla.47 - gsmtp
[C] QUIT
[S] 221 2.0.0 closing connection bla.47 - gsmtp
Mail sent successfully

Chinese is also accepted:

[C] MAIL FROM: <世界@example.com> SMTPUTF8
[S] 250 2.1.0 OK bla.19 - gsmtp

PS: mailsend does not check if a from-mailaddress is plain US ASCII / Latin, which it should do IMHO; now mail with -f Lütéé@example.com is sent to a non-SMTPUTF8 mail server, it is accepted, and then it is gone / lost.