Скачал следующий пример:Отправка почты с помощью примера javax.mail
https://app.box.com/shared/etj0lts287r5lc1hqeex
Когда я выполнил .jar файл напрямую, он работал отлично. Но при запуске проекта с использованием Netbeans 7.0 он выдает ошибку:
error: could not connect to SMTP host:smtp.gmail.com,port:465
В чем может быть проблема?
это мой код на кнопку actionperformed собственной недействительным sendButtonActionPerformed (java.awt.event.ActionEvent EVT) {
boolean isSent = true;
try {
Properties properties = new Properties();
properties.setProperty("mail.smtp.submitter", txtfrom.getText());
properties.setProperty("mail.smtp.auth", "true");
properties.setProperty("mail.smtp.host", txthostName.getText());
properties.put("mail.smtp.user", txtfrom.getText());
properties.put("mail.smtp.port", txtPort.getText());
properties.put("mail.smtp.socketFactory.port", txtPort.getText());
properties.put("mail.smtp.starttls.enable","true");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.socketFactory.fallback", "false");
Authenticator mailAuthenticator = new MailAuthenticator();
Session mailSession = Session.getDefaultInstance(properties,mailAuthenticator);
Message message = new MimeMessage(mailSession);
Transport transport = mailSession.getTransport("smtps");
transport.connect("smtp.gmail.com",465,"[email protected]","12345");
InternetAddress fromAddress = new InternetAddress(txtfrom.getText());
InternetAddress toAddress = new InternetAddress(txtto.getText());
message.setFrom(fromAddress);
message.setRecipient(RecipientType.TO, toAddress);
message.setSubject(txtsubject.getText());
message.setText(txtcontent.getText());
Transport.send(message);
} catch (Exception e) {
lblInfo.setText("ERROR:" + e.getMessage());
isSent = false;
}
if(isSent == true) {
sendButton.setEnabled(false);
lblInfo.setText("Your e-mail has been sent.");
}
}
Я пытаюсь изменить номер порта ... посмотрите, может быть, может помочь вам: https: //support.google.com/mail/answer/13287? Hl = ru – ZaoTaoBao
Я попытался изменить номер порта, но тот же ошибка выбрасывается. –