看者有分...

SEASKYLONG 2004-12-15 11:20:29
是关于JSP在线发送电子邮件的.但是发送是成功了.而邮件里是乱码.为什么呢?

源码在
http://community.csdn.net/Expert/topic/3646/3646490.xml?temp=.1545679
...全文
70 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
CALM 2004-12-15
  • 打赏
  • 举报
回复
应该指定编码
lockljd 2004-12-15
  • 打赏
  • 举报
回复
http://www.netyi.net/in.asp?id=lockllb//大量的教程!几乎包含了有关于计算机的一切!!!!!!

sanyou98 2004-12-15
  • 打赏
  • 举报
回复
up
wei_z 2004-12-15
  • 打赏
  • 举报
回复
up
wei_z 2004-12-15
  • 打赏
  • 举报
回复
你是不是经过了两次中文转码的过滤!所以又转回来了。
xiaoyaozgc 2004-12-15
  • 打赏
  • 举报
回复
你应当指定编码方式
SEASKYLONG 2004-12-15
  • 打赏
  • 举报
回复
<%@ 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>
这是代码.如果到那里也有分送.解决一起结贴.

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧