0
當內容具有重音字符時,使用JMS發送電子郵件時發生問題。JMS郵件服務器的字符編碼問題
消息被推送到隊列並作爲對象消息放置。監聽者收聽消息並將其發送給郵件服務器。
一切工作正常我的本地服務器上。但是,當我在Solaris生產服務器上運行相同的操作時,重音字符會變得混亂。在電子郵件內容中,它爲DeLeón打印DeLe n。基本上,重音字符沒有被編碼,並顯示一個問號[ ]。
在這個問題上的任何幫助是高度讚賞。以下是我用來傳遞消息的代碼。
private void sendEmailMessage(EmailBean emailBean) {
System.out.println("SendReceivedEmailMessages::sendEmail()");
try {
if (emailBean.getFromAddresses() != null && !emailBean.getFromAddresses().isEmpty()) {
Properties existingProperties = session.getProperties();
existingProperties.put("mail.from", emailBean.getFromAddresses());
session = Session.getInstance(existingProperties);
}
String DELIMITER = ";";
String subject = emailBean.getSubject();
String msgText = emailBean.getBody();
MimeMessage message = new MimeMessage(session);
message.setSubject(subject);
message.setContent(message, "text/html");
InternetAddress[] toAddressList = parseRecipients(emailBean.getToAddresses(), DELIMITER);
InternetAddress[] ccAddressList = parseRecipients(emailBean.getCcAddresses(), DELIMITER);
InternetAddress[] bccAddressList = parseRecipients(emailBean.getBccAddresses(), DELIMITER);
message.setRecipients(javax.mail.Message.RecipientType.TO, toAddressList);
message.addRecipients(javax.mail.Message.RecipientType.CC, ccAddressList);
message.addRecipients(javax.mail.Message.RecipientType.BCC, bccAddressList);
Multipart multipart = new MimeMultipart();
if (emailBean.getFileByteArrRegular() != null) {
addAttachmentFiles(multipart, emailBean.getFileByteArrRegular(), emailBean.getFilename() + "_Regular.docx", msgText);
}
if (emailBean.getFileByteOthers() != null) {
addAttachmentFiles(multipart, emailBean.getFileByteOthers(), emailBean.getFilename() + ".docx", msgText);
} else {
addAttachmentFiles(multipart, null, null, msgText);
}
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException ex) {
Logger.getLogger(SendReceiveEmailMessages.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
Logger.getLogger(SendReceiveEmailMessages.class.getName()).log(Level.SEVERE, ex.getStackTrace()[0].toString(), ex);
} catch (Exception ex) {
Logger.getLogger(SendReceiveEmailMessages.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
Logger.getLogger(SendReceiveEmailMessages.class.getName()).log(Level.SEVERE, ex.getStackTrace()[0].toString(), ex);
}
}
你的問題很可能是在調用'emailBean.setBody(messageBody)'的代碼中,因爲你的消息體已經在那個時候編碼了。 – 2015-03-19 01:59:29
嗯.... EmailBean是一個簡單的pojo與'私人絃樂體;'變量。所以它只是我設置爲body變量的字符串格式的html文本。 – 2015-03-19 16:55:27