SOLVED [11.3-U3.1] Email error: /middlewared[75]: 'ascii' codec can't encode character

vryeksksk

Dabbler
Joined
Apr 20, 2018
Messages
10
Hi, I'm trying to script some emails but I hit a roadblock with this one.
For simplicity sake i'm not going to post full script I'm running for rclone but only test email that produces exact same error and is just a shortened version of what is in my script.

Code:
{
printf '%s\n' "From: example@domain.pl
To: example@domain.pl
Subject: TEST
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"ZZ_/afg6432dfgkl.9453551q\"
--ZZ_/afg6432dfgkl.9453551q
Content-Type: text/plain; charset=\"UTF-8\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
"
printf '%s\n' "TEEEEEST"
    printf '%s\n' "--ZZ_/afg6432dfgkl.9453551q--"

    } | sendmail -t -oi


This email is sent and arrives without any issue but when i change the TEEEEST line to this:

Code:
printf '%s\n' "ą, ć, ę, ł, ń, ó, ś, ź, ż."


It produces this error in the maillog:

Code:
Jun  7 11:01:43 freenas /middlewared[75]: sending mail to example@domain.pl
Content-Type: multipart/mixed
MIME-Version: 1.0
Subject: TEST
From: example@domain.pl
To: example@domain.pl
Date: Sun, 07 Jun 2020 09:01:43 -0000
Message-ID: <freenas-20200607.090143.210796.b'_d4R'@freenas.home>
X-Mailer: FreeNAS
X-FreeNAS-Host: freenas
Jun  7 11:01:43 freenas /middlewared[75]: Failed to send email to example@domain.pl: 'ascii' codec can't encode character '\u0105' in position 532: ordinal not in range(128)


Should I report it as a bug or am I making a mistake somewhere?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
You set "Content-Transfer-Encoding: 7bit", so you are limited to 7 bit ASCII. You need to encode your text yourself, Sendmail won't do that for you. Sendmail is a Mail Transport Agent (MTA), preparing and specifically encoding the message for transport is the job of the Mail User Agent (MUA), i.e. your script in this case. Even with Transfer-Encoding 8bit UTF-8 will probably not work IIRC.
 

vryeksksk

Dabbler
Joined
Apr 20, 2018
Messages
10
You set "Content-Transfer-Encoding: 7bit", so you are limited to 7 bit ASCII. You need to encode your text yourself, Sendmail won't do that for you. Sendmail is a Mail Transport Agent (MTA), preparing and specifically encoding the message for transport is the job of the Mail User Agent (MUA), i.e. your script in this case. Even with Transfer-Encoding 8bit UTF-8 will probably not work IIRC.

Well that was easy, thank you. That put me on a right track and I got it working after encoding it with base64 (stole the function from here).


Code:
encoded_contents="$(base64 <<< "ą, ć, ę, ł, ń, ó, ś, ź, ż.")"

{
printf '%s\n' "From: example@domain.pl
To: example@domain.pl
Subject: TEST
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"ZZ_/afg6432dfgkl.9453551q\"
--ZZ_/afg6432dfgkl.9453551q
Content-Type: text/plain; charset=\"UTF-8\"
Content-Transfer-Encoding: base64
Content-Disposition: inline
"
printf '%s\n' "${encoded_contents}"
    printf '%s\n' "--ZZ_/afg6432dfgkl.9453551q--"

    } | sendmail -t -oi

 
Top