我正在尝试使用SMTP发送忘记密码的电子邮件。但是我得到如下的例外
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
以下是java代码
String to = email;
String from = "XXXXXXX@gmail.com";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));
message.setSubject("This is the Subject Line!");
message.setContent("<h1>This is actual message</h1>", "text/html");
Transport.send(message);
}
任何人都可以告诉我如何使用SMTP发送电子邮件