dcsimg
JSP/Servlet sending email with accented subject, how to send it correctly by email.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   AT_LE
Posted On:   Friday, February 22, 2002 03:00 AM

<%@ page import="java.text.*" %> <%@ page import="java.util.*" %> <%@ page import="java.util.Properties" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail.internet.*" %> <% String subject = "è..."; String msgText = "Test ... é à è ù !!!"; Properties props = new Properties(); props.put("mail.smtp.host", "xxx.xxx.com"); Session mailsession = Session.getDefaultInstance(props, null); mailsession.setDebug(true); try { InternetAddress toAddress = new InternetAddress("   More>>
			
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Properties" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>







<%
String subject = "è...";
String msgText = "Test ... é à è ù !!!";

Properties props = new Properties();
props.put("mail.smtp.host", "xxx.xxx.com");

Session mailsession = Session.getDefaultInstance(props, null);
mailsession.setDebug(true);

try {
InternetAddress toAddress = new InternetAddress("ATL to test ");
InternetAddress fromAddress = new InternetAddress("ATL from ");

Message msg = new MimeMessage(mailsession);
msg.addRecipient(Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setFrom(fromAddress);
msg.setContent(msgText, "text/html");
//msg.setText(msgText);

Transport.send(msg);
out.println("Email has been sent:
"+
"From: " + fromAddress + "

" +
"To: " + toAddress + "

" +
"Subject: " + subject + "

" +
"
				
" +
msgText +
"
");
}
catch (MessagingException e) {
out.println("Email has not been sent: " + e);
e.printStackTrace();
}
%>



the arrived email has the subject:
=?Cp1252?Q?=E8...?= instead of è...
   <<Less

Re: JSP/Servlet sending email with accented subject, how to send it correctly by email.

Posted By:   AT_LE  
Posted On:   Friday, February 22, 2002 07:09 AM

I found the solution:


create a MimeMessage instead of Messsage:

MimeMessage msg = new MimeMessage(mailsession);


then


msg.setSubject(subject, "ISO-8859-1");

Re: JSP/Servlet sending email with accented subject, how to send it correctly by email.

Posted By:   Chandra_Patni  
Posted On:   Friday, February 22, 2002 03:56 AM

Are you trying to print the message you've sent to console with windows encoding? Is so, use an ide where you can see the fonts.


Try changing your message encoding as follows. However, I could send message without seeing any probem.


message.setHeader("Content-Transfer-Encoding", "8bit");

About | Sitemap | Contact