witam serdecznie, mam problem z java mail. Napisalem programik ktory powinien wysylac maile obslugujac autoryzacje na serwerze smtp. ponizej wrzucam kod:
procedura wysylania:
private void sendButActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Properties properties = System.getProperties();
properties.put("mail.smtp.host", hostTF.getText());
if (!portTF.getText().isEmpty()) {
properties.put("mail.smtp.port", portTF.getText());
}
else {
properties.put("mail.smtp.port", "25");
}
if (!userTF.getText().isEmpty()) {
properties.put("mail.smtp.auth", "true");
Authenticator isAuth = new MailAuthenticator();
Session session = Session.getInstance(properties, isAuth);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromTF.getText()));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(toTF.getText()));
msg.setSubject(subTF.getText());
msg.setText(msgTA.getText());
Transport.send(msg);
}
}
catch (MessagingException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
finally {
dispose();
}
}
i statyczna klasa odpowiadajaca za autoryzacje na serwerze:
static class MailAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userTF.getText(),passTF.getText());
}
}
problem polega na tym ze kiedy probuje sobie wyslac maila od siebie do siebie otrzymuje blad:
"could not connect to SMTP host: poczta.o2.pl, port: 25"
dziwne to troche bo podaje wlasciwe dane a w konfiguracji smtp na o2.pl napisali wlasnie port 25...
moze w kodzie mam jakis blad? bylby ktos na tyle dobry zeby to obejrzec i naprowadzic mnie troszke? bo google nic nie pomogl :/