javamail发送邮件提示404错误?高分请教
用javamail写了一个发送邮件的程序,但是发送后提示404错误,不知道怎么回事。向高手请教。
页面代码:
<%@ page language= "java " contentType= "text/html; charset=gb2312 "
pageEncoding= "gb2312 "%>
<%@ page import= "javax.activation.* "%>
<%@ page import= "javax.mail.internet.* "%>
<%@ page import= "java.util.* "%>
<%@ page import= "javax.mail.* "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<%
class MyAuthenticator
extends javax.mail.Authenticator {
private String strUser;
private String strPwd;
public MyAuthenticator(String user, String password) {
this.strUser = user;
this.strPwd = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(strUser, strPwd);
}
}
%>
<%
String subject = request.getParameter( "title ");
String subtext = request.getParameter( "content ");
if(subject!=null && !subject.equals( " ") && subtext!=null && !subtext.equals( " "))
{
try {
Properties props = new Properties();
props.put( "mail.smtp.host ", "smtp.163.com ");
props.put( "mail.smtp.auth ", "true ");
MyAuthenticator myauth = new MyAuthenticator( "username ", "password ");
Session sessions = Session.getDefaultInstance(props, myauth);
MimeMessage newMessage = new MimeMessage(sessions);
newMessage.setFrom(new InternetAddress(
"yundazyx@163.com "));
newMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress( "yundazyx@163.com "));
newMessage.setSubject(subject);
newMessage.setSentDate(new Date());
newMessage.setText(subtext);
newMessage.saveChanges();
Transport transport = sessions.getTransport( "smtp ");
transport.connect( "smtp.163.com ", "username ", "password ");