simple-mail
simple-mail copied to clipboard
Attachment file with non-ASCII characters in name breaks mail header
If the filename of an attached file contains non-ASCII characters (I tested with German umlauts äöü), the file is encoded in Base64, but the mail header is missing the field "Content-Transfer-Encoding: base64" for the attachment, so the receiver can only view the scrambled Base64 content. Manually setting the encoding of the attachment does not help.
Under normal circumstances, MimeAttachment(QFile *) works fine, the attachment is automatically encoded in Base64 and the mail header is correct.
The code I'm using for sending the mail (simplified):
Sender smtp(smtpServer, 465, Sender::SslConnection);
smtp.setUser(smtpUser);
smtp.setPassword(password);
EmailAddress from(senderAddress, senderName);
EmailAddress to(receiverAddress, receiverName)ö
MimeMessage message;
message.setSender(from);
message.addTo(to);
message.setSubject(subject);
MimeText *text = new MimeText(bodyText);
message.addPart(text);
MimeAttachment *attachment = new MimeAttachment(new QFile(entry.attachmentFile));
// added for testing
attachment->setEncoding(MimeAttachment::Base64);
message.addPart(attachment);
smtp.sendMail(message);
I took a quick look at the library itself, and it seems that at least in the MimePart::write function, the header field is set correctly. Not really sure where to go from here.
is "Content-Transfer-Encoding: base64" header missing for the filename, or the file name isn't being encoded?
The header is missing. The file name and contents are properly encoded.
See below two examples of the same file being sent - a text file with the content "abcdefg", but once the file is named testFile and once testfäöü
Let me know if you need any more info.
Raw mail source for file without umlauts:
...
--3eb453d25e5b4e5f9a4938fc8cb4e189
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
TestBody
--3eb453d25e5b4e5f9a4938fc8cb4e189
Content-Type: text/plain; name="testFile"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="testFile"
YWJjZGVmZwo=
--3eb453d25e5b4e5f9a4938fc8cb4e189--
Raw mail source for file without umlauts:
...
--25a9eab56f03403088b99a221f7d209c
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
TestBody
--25a9eab56f03403088b99a221f7d209c
Content-Type: text/plain; name="testfäöü"
Content-Disposition: attachment; filename="testfäöü"
YWJjZGVmZwo=
--25a9eab56f03403088b99a221f7d209c--
should be fixed by your MR