Witam,
W oparciu o materialy znalezione na google, przygotowalem sobie cos takiego co
powinno wyslac mi email, oto kod:
private static final String SMTP_HOST_NAME = "poczta.o2.pl";
private static final String SMTP_AUTH_USER = "pvsp";
private static final String SMTP_AUTH_PWD = "mojehaslo";
private static final String emailMsgTxt = "You have new request.";
private static final String emailSubjectTxt = "Info";
private static final String emailFromAddress = "[email protected]";
//metoda wymaga przerobienia tak aby pobierala z bazy danych email
private String[] getEmailAdresses(){
String[] emailAdresses={"[email protected]"};
return emailAdresses;
}
public void sendEmailNotyfication()throws MessagingException{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(emailFromAddress);
msg.setFrom(addressFrom);
String[] recipients=getEmailAdresses();
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject("ddd");
msg.setContent("vvv", "text/plain");
Transport.send(msg);
}
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
Natomiast wywala mi wyjatek ale starsznie marnie opisany bo tresc komunikatu
"smtp" co nie jest zbyt dokladnym opisem, czy ktos sie spotkal juz z takim
problemem, jezeli tak to prosil bym w jakas wskazowke,
Program jest na podstawie tego materialu
www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274
a dokladnie o ten przyklad poniezej z autoryzacja