Witam
Moj kod na wysylanie maili wyglada nastepujaco:
try{
String host = "poczta.o2.pl";
String username = "konto";
String password = "asasas";
Authenticator auth = new MessageAuthenticator("username_1980", "password");
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", true);
Session session = Session.getInstance(props, auth);
MimeMessage mm = new MimeMessage(session);
mm.setContent("Test", "text/plain");
mm.setSubject("test");
Address address = new InternetAddress("[email protected]");
mm.setFrom(address);
mm.addRecipient(RecipientType.TO, address);
Transport.send(mm);
return true;
}
catch (NoSuchProviderException ex) {
}
catch (MessagingException ex) {
}
private class MessageAuthenticator extends Authenticator {
public MessageAuthenticator(String u, String p){
username = u;
password = p;
}
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
private String username, password;
}
Kod dziala jesli uruchomie go z aplikacji "stand-alone". Natomiast jesli wlepie ten kod w metodzie EJB to juz mail sie nie wysyla. Wyskakuje wtedy jedynie tekst "DEBUG SMTP: QUIT failed with 250".
Poszukalme ale nie znalazlem rozwiazania. Niby jaka roznica jest pomiedzy JavaMail zaimplementowana w GlassFish a osobno sciagnieta biblioteka?