用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(
"[email protected]")); newMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]")); newMessage.setSubject(subject);
newMessage.setSentDate(new Date());
newMessage.setText(subtext); newMessage.saveChanges();
Transport transport = sessions.getTransport("smtp");
transport.connect("smtp.163.com", "username", "password");
transport.sendMessage(newMessage, newMessage.getAllRecipients());
transport.close(); %>
<p>send mail success<p>
<%
} catch (MessagingException m) {
out.println(m.toString()); }
}
%>结果提示的错误是:
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
页面代码:
<%@ 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(
"[email protected]")); newMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]")); newMessage.setSubject(subject);
newMessage.setSentDate(new Date());
newMessage.setText(subtext); newMessage.saveChanges();
Transport transport = sessions.getTransport("smtp");
transport.connect("smtp.163.com", "username", "password");
transport.sendMessage(newMessage, newMessage.getAllRecipients());
transport.close(); %>
<p>send mail success<p>
<%
} catch (MessagingException m) {
out.println(m.toString()); }
}
%>结果提示的错误是:
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
解决方案 »
- JDBC连接microsoft sqlserver要怎么连啊
- jsp图片存数据库问题:路径问题
- 大家都来说说,java 应用开发大家都用什么开发工具。
- JSP的乱码
- 执行sql后怎么直接得到数值,而不是string
- 谁知道如何解决JBuider9的汉字不能显示问题。有布丁吗?谢谢。给分。
- 中间件方面技术网站初步建立,散分!!
- 请问:javax.servlet.include.path_info什么时候会有值?
- 关于读、写文件的问题
- 求助大佬,解决一下Mybatis问题
- jsf标签<h:panelGroup ...></panelGroup >有什么作用?
- validator框架,还没提交就出现验证错误提示,想了个原因,不知道是不是!
另外,将你获取的HTML部分程序看一下,是否能正常获取