Всем привет! Есть небольшая проблема, не отправляется имейл из сервлета. Используется java 1.4, tomcat 4.1. Подозреваю, что проблема в томкате, т.к. в тестовом варианте все отправляется. Может кто сталкивался с подобной проблемой?
public class MailServlet extends HttpServlet
{
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
{
try {
sendMail("smtpHost", "user", "pass", "from", "to", "subject","text");
} catch (Exception e) {
}
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{}
public static void sendMail(String smtpHost,String username,String password,String senderAddress,String recipientsAddress,String subject,String text ) throws Exception
{
MailAuthenticator auth = new MailAuthenticator(username, password);
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session = Session.getDefaultInstance(properties, auth);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(senderAddress));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientsAddress, false));
msg.setSubject(subject);
msg.setText(text);
msg.setHeader("Recall", "Recall");
msg.setSentDate(new Date( ));
Transport.send(msg);
}
}
class MailAuthenticator extends Authenticator
{
private final String user;
private final String password;
public MailAuthenticator(String user, String password)
{
this.user = user;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(this.user, this.password);
}
}
Ошибка - `java.lang.SecurityException: Access to default session denied
рекомендуют поменять Session.getDefaultInstance на Session.getInstance, тогда другая ошибка javax.mail.MessagingException: Exception reading response;
nested exception is:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: Certificate signature validation failed
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости