请大哥看看,javamail下的smtp认证应该怎么做啊?(急!!!)
我的代码:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*"%>
<%@ page import="javax.activation.*"%>
<html>
<head>
<title>java mail</title>
</head>
<body>
<%
String host="smtp.163.com";
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.smtp.host",host);
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.user","myuser");
props.put("mail.smtp.password","mypass");
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.setSentDate(new Date());
msg.setText(body);
Transport.send(msg);
%>
邮件已发送至:<%=to%><br>
从:<%=from%><br>
使用主机:<%=host%><br>
subject:<%=subject%><br>
content:<%=body%><br>
</body>
</html>
报错:
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.AuthenticationFailedException
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)