发送邮件后.收到的是乱码.大家帮我一下.怎么解决?下面是代码..在线等..
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="javax.mail.*"%>
<%@ page import="javax.mail.internet.*"%>
<%@ page import="javax.activation.*"%>
<%@ page import="java.util.*"%>
<HTML>
<head> <TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<BODY>
<%!
//byte[] subjectTemp= request.getParameter("Subject").getBytes("ISO8859_1");
public class PopupAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username, password;
username = "user";
password = "pass";
return new PasswordAuthentication(username, password);
}
}
%>
<%!
public String toChi(String input)
{
try
{
byte[] bytes = input.getBytes("ISO8859-1");
return new String(bytes);
}
catch(Exception ex)
{
}
return null;
}
%>
<%
try{
String name = request.getParameter("Name");
String subject = request.getParameter("Subject");
String Hi=request.getParameter("Body");
byte[] tmpbyte=Hi.getBytes("ISO8859_1");
Hi=new
String(tmpbyte);
// out.print(Hi);
//String body = (request.getParameter("Body").getBytes("ISO8859-1"));
Properties props = new Properties();
Session sendMailSession; Store store;
Transport transport;
props.put("mail.smtp.host","yourhost");
props.put("mail.smtp.auth","true");
Authenticator auth = new PopupAuthenticator();
sendMailSession = Session.getInstance(props,auth);
sendMailSession.setDebug(true);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress("frommail"));
newMessage.setRecipient(
Message.RecipientType.TO, new InternetAddress("tomail"));
newMessage.setSubject(subject);
newMessage.setSentDate(new Date());
//String body = ("hello are you你好啊.?");
newMessage.setText(Hi);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
} catch(MessagingException m) {
out.println(m.toString());
}
%>
</BODY>
</HTML>