错误:javax.mail.AuthenticationFailedException:连接失败

时间:2017-03-25 08:15:38

标签: java email smtp

我很抱歉再次出现此错误,但无法找到任何解决方案。我想从java应用程序发送邮件。我已经写了相同的以下函数,它显示:javax.mail.AuthenticationFailedException:连接失败。 我确定这个功能有问题,但不确切知道。请帮忙。

import java.util.*;
import javax.mail.*;
javax.mail.internet.*;
import javax.activation.*;

public class SendMail {


public static void sendm(String from,String subject,String messagef) {    

      String to = "support@email.com";
      String from1 = from;   
      Properties props = new Properties();
      props.put("mail.smtp.host", "smtp.gmail.com");
      props.put("mail.smtp.port", "587");
      props.put("mail.stmp.user" , "support@email.com");
      props.put("mail.smtp.password", "password");
      props.put("mail.smtp.auth", "true");
      props.put("mail.debug", "false");
      props.put("mail.smtp.ssl.enable", "true");

      Session session = Session.getDefaultInstance(props);

      try {
           MimeMessage message = new MimeMessage(session);
           message.setFrom(new InternetAddress(from1));
           message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
           message.setSubject(subject);
           message.setText(messagef);
           Transport.send(message);
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }

}

0 个答案:

没有答案