本人写的发邮件程序发给163.com老是不行,还有其他的如雅虎也不行,但是发给自己的邮件服务器可以请指点
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SEND1 extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb2312");
String from = request.getParameter("from");
String to = request.getParameter("to");
String subject = request.getParameter("subject");
String context = request.getParameter("context");
String type=request.getParameter("type");
// 确定要发送的邮件服务器的地址
String mailserver = "163.com";
// 设置邮件的传输协议
try {
Properties prop = System.getProperties();
prop.put("mail.smtp.host", mailserver);
// 建立邮件发送的连接
Session session = Session.getDefaultInstance(prop, null);
// 创建发送的信息的载体
Message msg = new MimeMessage(session);
// 设置相关的邮件属性
msg.setFrom(new InternetAddress(from));
// 点到点的发送
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
/*
* //群发 msg.setRecipients(Message.RecipientType.TO, new
* InternetAddress[]{new InternetAddress(to),new
* InternetAddress(to)}); //借助循环的标准发送
*/
msg.setSubject(subject);
msg.setSentDate(new Date());
//判断发送的Mime类型
Multipart mp=new MimeMultipart();
MimeBodyPart mbp=new MimeBodyPart();
//设置邮件发送数据的类型
mbp.setContent(context, type+";charset=GB2312");
//text/plain或text/html;charset=GB2312,将发送的数据进行封装
mp.addBodyPart(mbp);
msg.setContent(mp);
// 发送
Transport.send(msg);
} catch (Exception e) {
}
out.print("send ok");
out.flush();
out.close();
}
}
下面是jsp页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JavaMail1.html</title>
</head>
<body>
<form action="SEND" method="post">
From:<input name="from" ><br>
TO:<input name="to" ><br>
Subject:<input name="subject" ><br>
Context:<textarea rows="40" cols="30" name="context"></textarea><br>
<input type="submit">
</form>
</body>
</html>
就不行了不知道是163收件箱的地址没写对还是别的试了好多都不行,请指点