关于邮件的问题
import
java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestMailServlet extends HttpServlet
{
public TestMailServlet()
{
super();
}
public void destroy()
{
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String tto = request.getParameter("to");
String ttitle = new String(((String) request.getParameter("title"))
.getBytes("iso8859-1"), "GBK");
String tcontent = new String(((String) request.getParameter("message"))
.getBytes("iso8859-1"), "GBK");
String tfrom =new String(((String) request.getParameter("from"))
.getBytes("iso8859-1"), "GBK");
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "true");
javax.mail.Session s = javax.mail.Session.getInstance(props);
MimeMessage message = new MimeMessage(s);
InternetAddress from;
try
{
from = new InternetAddress(tfrom);
message.setFrom(from);
InternetAddress to = new InternetAddress(tto);
message.setRecipient(Message.RecipientType.TO, to);
message.setSubject(ttitle);
message.setText(tcontent);
message.saveChanges();
javax.mail.Transport transport = s.getTransport("smtp");
System.out.println("yyyyyyyyyyyyyyy");
transport.connect("smtp.163.com",tfrom, "321456789");
System.out.println("444444444444444444");
transport.sendMessage(message, message.getAllRecipients());
System.out.println("rrrrrrrrrrrrrrrrr");
transport.close();
System.out.println("成功");
} catch (Exception e)
{
e.printStackTrace();
}
}
public void init() throws ServletException
{
}
}
*****************************************************************************************************
异常~```
yyyyyyyyyyyyyyy
javax.mail.MessagingException: 502 Error: command not implemented
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:915)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:417)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at com.test.mail.TestMailServlet.doPost(TestMailServlet.java:65)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:710) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)