Discussion:
Random Special Characters in mail body
(too old to reply)
mando.stathaki@gmail.com
2016-10-17 08:05:33 UTC
Permalink
Hello,

My setup consists of a centos 6.8 machine with postfix 2.6.6 installed. I have a PHP 5.5.38 application which sends mails. The php application creates an .sh file with the following content:

#!/bin/ksh

(
export MAILFROM="Some_Greek_Mailfrom<***@yyyyy.gr>"
export MAILTO="***@yyyyy.gr, ***@gmail.com"
export BCC="***@gmail.com"
export SUBJECT="Some_Greek_Subject"
export BODY="BIG HTML BODY"
export MAILPART_BODY=`uuidgen`

(

echo "From: $MAILFROM";
echo "To: $MAILTO";
echo "Bcc: $BCC";
echo "Subject: $SUBJECT";
echo "MIME-Version: 1.0";
echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\"";
echo "";
echo "--$MAILPART_BODY";
echo "Content-Type: text/plain; charset=utf-8";
echo "";
echo "You need to enable HTML option for email";
echo "--$MAILPART_BODY";
echo "Content-Type: text/html; charset=utf-8";
echo "Content-Transfer-Encoding: 8bit";
echo "Content-Disposition: inline";
echo "";
echo $BODY;
echo "--$MAILPART_BODY--";
) | /usr/sbin/sendmail $MAILTO, $BCC
)

Then I call another function from php which executes the .sh file and the mail is sent.
I must mention that the BODY that is produced by the php application is very large (>1000) and is always html.
I must also mention that I had no problems until 2 weeks ago where the problem with the random special characters in the mail body started appearing.
Until the problem appears, there was no authentication with the relay (openrelay). This changed when the guys that administer the relay server configured it to always use authentication.
I use SASL to authenticate to the relay.
Now in ALL the messages that are sent by postfix (postfix is configured only to send) there are random special characters inserted like this:

"Το όÏ �ι μέχρι τώρα μας απαντάει η Facebook, εξηγείται στο γεγονός "

I have tried almost everything (changed content-transfer-encoding, postfix configuration options etc) but same problem.

Also I have run a network trace and confirmed that the problem is in my side. The characters are displayed in the trace.

I think it's postfix's behavior but I have no clue how to deal with this issue of large line length in the mail body.

Any help?

Thanks.
d***@gmail.com
2017-01-21 13:09:02 UTC
Permalink
Post by ***@gmail.com
Hello,
#!/bin/ksh
(
export SUBJECT="Some_Greek_Subject"
export BODY="BIG HTML BODY"
export MAILPART_BODY=`uuidgen`
(
echo "From: $MAILFROM";
echo "To: $MAILTO";
echo "Bcc: $BCC";
echo "Subject: $SUBJECT";
echo "MIME-Version: 1.0";
echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\"";
echo "";
echo "--$MAILPART_BODY";
echo "Content-Type: text/plain; charset=utf-8";
echo "";
echo "You need to enable HTML option for email";
echo "--$MAILPART_BODY";
echo "Content-Type: text/html; charset=utf-8";
echo "Content-Transfer-Encoding: 8bit";
echo "Content-Disposition: inline";
echo "";
echo $BODY;
echo "--$MAILPART_BODY--";
) | /usr/sbin/sendmail $MAILTO, $BCC
)
Then I call another function from php which executes the .sh file and the mail is sent.
I must mention that the BODY that is produced by the php application is very large (>1000) and is always html.
I must also mention that I had no problems until 2 weeks ago where the problem with the random special characters in the mail body started appearing.
Until the problem appears, there was no authentication with the relay (openrelay). This changed when the guys that administer the relay server configured it to always use authentication.
I use SASL to authenticate to the relay.
"Το όÏ �ι μέχρι τώρα μας απαντάει η Facebook, εξηγείται στο γεγονός "
I have tried almost everything (changed content-transfer-encoding, postfix configuration options etc) but same problem.
Also I have run a network trace and confirmed that the problem is in my side. The characters are displayed in the trace.
I think it's postfix's behavior but I have no clue how to deal with this issue of large line length in the mail body.
Any help?
Thanks.
Hi

It is not "random" but a charset error.

It would be more easy to tell you what's wrong with a sample mail generated by the source code.

I think the "Content-Transfer-Encoding: 8bit" line should be in the mail header too.

And remember that non ascii subject must be encoded with base64 or quoted printable.

Regards

Victor

Loading...