原代码如下:
sendmail页面
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>利用java发送电子邮件</title>
</head>
<body>
<center>利用java发送电子邮件</center>
<hr>
<form action="sendmail.jsp" method="post">
收信人邮箱:
<input type="text" name="to" size="30"><br>
寄信人邮箱:
<input type="text" name="from" size="30"><br>
主题:
<input type="text" name="subject" size="30"><br>
正题:<br>
<textarea cols="40" rows="8" name="body">
</textarea><br>
<input type="submit" name="submit" value="发送">
<input type="reset" name="reset" value="重置">
</form>
</body>
</html>
sendmail.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*,javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JSP Javamail的使用</title>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String host="220.181.12.16";
String to=request.getParameter("to");
String from = request.getParameter("from");
String subject=request.getParameter("subject");
String body=request.getParameter("body");
boolean sessionDebug=false;
java.util.Properties props=System.getProperties();
props.put("mail.host",host);
props.put("mail.transport.protocol","smtp");
javax.mail.Session mailSession=javax.mail.Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
Message msg =new MimeMessage(mailSession);
//设置发信人
msg.setFrom(new InternetAddress(from));
//设置收信人,可以有多个收信人
InternetAddress[] address={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,address);
//设置主题
msg.setSubject(subject);
//设置发信时间
msg.setSentDate(new Date());
//设置邮件MIME type
msg.setText(body);
//邮件发送
Transport.send(msg);
%>
电子邮件已发送至:<%= to %><br>
从:<%= from %><br>
使用主机:<%= host %>
邮件主题:<%= subject %>
邮件内容:<%= body %>
</body>
</html>
出现下面的错误:
javax.servlet.ServletException: 553 authentication is required,smtp9,wKjAEDLATB1XFTVEWQ5bGw==.14497S2 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.study.sendmail_jsp._jspService(sendmail_jsp.java:115) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
com.sun.mail.smtp.SMTPSendFailedException: 553 authentication is required,smtp9,wKjAEDLATB1XFTVEWQ5bGw==.14497S2 com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333) com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906) com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:535) javax.mail.Transport.send0(Transport.java:151) javax.mail.Transport.send(Transport.java:80) org.apache.jsp.study.sendmail_jsp._jspService(sendmail_jsp.java:89) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
谢谢大家帮忙看下该怎么改啊!!
----------------解决方案--------------------------------------------------------
没密码呀!做个有密码的。
----------------解决方案--------------------------------------------------------