Я пытаюсь отправить электронное письмо с подтверждением пользователей моего веб-приложения, но я получаю следующее сообщение об ошибке:Отправка электронной почты из Java
PKIX здание путь не удалось: sun.security.provider.certpath.SunCertPathBuilderException: не удалось найти правильный путь сертификации к запрошенной цели
Это мой Java класс:
package it.bcsoft.onlinestore.mail;
import java.util.Properties;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
public class EmailSender {
public static boolean sendEmail(String from, String pass, String message, String[] to)
{
String host="smtp.gmail.com";
Properties props= System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", 25);
props.put("mail.smtp.auth", "true");
Session session= Session.getDefaultInstance(props, null);
MimeMessage mime= new MimeMessage(session);
try {
mime.setFrom(new InternetAddress(from));
InternetAddress[] toAddress= new InternetAddress[to.length];
for(int i=0; i<to.length; i++)
{
toAddress[i]= new InternetAddress(to[i]);
}
for(int i=0; i<toAddress.length;i++)
{
mime.addRecipient(RecipientType.TO, toAddress[i]);
}
mime.setSubject("Mail from onlinestore");
mime.setText(message);
Transport transport= session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(mime, mime.getAllRecipients());
transport.close();
return true;
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}
не установлен какой-либо SMTP-сервер на моем компьютере, и я с помощью Java 1.7
Я пробовал уже со всеми тремя портами «587,25 и 465» то же самое –
Посмотрите сообщение в блоге, которое я только что добавил, и попытайтесь подключиться к SMTP-серверу так, как он описывает. – Timo
Я пробовал оба примера, TLS и SSL, он всегда меняет ту же ошибку –