Transport.send(javax.mail.AuthenticationFailedException:连接失败)

时间:2016-02-28 11:20:54

标签: java javamail

我一直在尝试向特定邮件发送反馈表单详细信息。我从用户那里获得名称,电子邮件和反馈文本。当他提交时,在我的Java课程中我执行以下操作

String name = request.getParameter("name");
String email = request.getParameter("email");
String feedback = request.getParameter("feedback");

System.out.println(name + "--" + email + "--" + feedback);

String to = "tester@gmail.com";

String from = email;

String host = "smtp.gmail.com";

Properties properties = System.getProperties();

properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.user", "name"); // User name
properties.put("mail.smtp.password", "pass"); // password
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");

// Get the default Session object.
Session session = Session.getDefaultInstance(properties);

response.setContentType("text/html");

MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));

message.addRecipient(Message.RecipientType.TO,
        new InternetAddress(to));

message.setSubject("FeedBack From" + name);

message.setText(feedback);
// Send message
Transport.send(message);
System.out.println("Sent");

这会产生错误

  

在Transport.send(javax.mail.AuthenticationFailedException:连接失败)。

我感到困惑的是它不是我需要的双向邮件,在这里我只需要将邮件发送给测试人员。我知道我在这里做错了但是无法识别它。

0 个答案:

没有答案