I have an email application that is supposed to send emails via
JavaMail API[
^] to a SMTP Server.
Now I need to send
emails with Arabic text and attachment. Arabic text is obviously build from
non-ASCII characters.
I can't get the Arabic text to be transmitted correctly. I'm pretty sure I'm not the first to do this so let's see if someone can help me here.
what works fine: sending plain text Arabic Email without Attachment.
(I post this because I want to show you what I'm doing here)
MimeMessage oMimeMessage = new MimeMessage(Session.getDefaultInstance(
getMimeMessageProperties(),
getMailAuthenticator()
));
oMimeMessage.setText(strBodyText, "UTF-8");
the message
without Attachment is send correctly, everybody is receiving it and the Arabic text is displayed correct.
what does not work: sending Arabic email with attachment
MimeMessage oMimeMessage = new MimeMessage(Session.getDefaultInstance(
getMimeMessageProperties(),
getMailAuthenticator()
));
MimeMultipart multipart = new MimeMultipart();
multipart.addBodyPart(getMessageBodyPart(oMail.getBody()));
Here the body of the message is made up:
private BodyPart getMessageBodyPart(final String strBody) throws MessagingException {
BodyPart oMessageBodyPart = new MimeBodyPart();
try {
oMessageBodyPart.setHeader("Content-Transfer-Encoding", "8bit");
String strEncoded = MimeUtility.encodeText(strBody,"utf8",null);
oMessageBodyPart.setDataHandler(new DataHandler(new MessageBodyDataSource(strEncoded)));
return oMessageBodyPart;
} catch (Exception oException) {
Logger.getLogger(SMTPParser.class).error("Can't process body text - will add plain text", oException);
oMessageBodyPart.setContent(strBody, "text/plain");
}
return oMessageBodyPart;
}
To my point of view I need to get the Header
Content-Transfer-Encoding: 8bit
across to the recipient.
But the email refuses and is received as 7bit - which ruins my day.
How do I get the Arabic body text transmitted correctly`(when attachments are involved)?