我正在使用java发送邮件但是当我在邮件正文中定义特殊字符时,它们在邮件中没有正确显示。我在邮件正文中写的字符:
Hereâ €™s the checklist of what
我收到的是:
Hereâ €™s the checklist of what
我使用这种方法在jQuery中获取消息体结构:
messageBody = $('.messageBody').html();
并使用AJAX调用将其传递给servlet:
$.ajax({
url: '/bin/mail',
data: {
emailTo: mailTo,
emailFrom: mailFrom,
attachmentPath: attachmentPath,
messageBody: messageBody,
emailSubject: emailSubject
},
dataType: 'text',
type: 'POST',
success: function(data){
$('.thankyou').show();
},
error: function() {
alert("Error");
}
})
在我的servlet中
String messageBody = (String)request.getParameter("messageBody");
MimeMessage mimemessage = new MimeMessage(session);
mimemessage.setHeader("Content-Encoding","UTF-8");
mimemessage.setRecipients(javax.mail.Message.RecipientType.TO, recipients.toArray(new InternetAddress[recipients.size()]));
mimemessage.setFrom(new InternetAddress(from));
mimemessage.setReplyTo(new InternetAddress[] { new InternetAddress(recipient) });
mimemessage.setSubject(subject);
mimemessage.setSentDate(new Date());
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(messageBody, "text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
mimemessage.setContent(multipart);
答案 0 :(得分:0)