[英]Intermittent connection error - Connection timed out - mysql jboss java
[英]Java SMTP mail - Connection timed out Error
我一直在開發一個程序,用於從基於桌面的Java應用程序發送電子郵件。
當我使用Google SMTP服務器(smtp.gmail.com)測試該程序時,該程序運行良好,但是,當我針對其他smtp服務器對其進行測試時,它會產生錯誤-
javax.mail.MessagingException: Could not connect to SMTP host:
smtp.collaborationhost.net, port: 465;
nested exception is:
java.net.ConnectException: Connection timed out: connect
我正在Eclipse中運行代碼。
以下是代碼段-
public class Emailer {
public static void main(String[] args) {
String name = "Testing";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.collaborationhost.net");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("qwert@xyzcompany.com","*******");
}
});
try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("qwert@xyzcompany.com"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("testgmail.com"));
message.setSubject("Generic Mail Test from Eclipse !!!");
message.setText("This is a Test Mail, sent from Local Eclipse System via Google SMTP server. \n\n" + "Regards, \n" + name + "." );
Transport.send(message);
System.out.println("Message Sent !!!");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.