on 02-22-2016 5:20 PM
Hello everyone,
I am trying to send an email from Outlook using Java Program[mentioned below] and I am facing some errors. Please let me know If I am doing something wrong or need changes for parameters. Any help highly appreciated
private static void sendEmail(String from, String to, String emailTemplate) {
try {
String host = "mail.sap.corp";
Properties properties = new Properties();
properties.put("mailsmtp.auth", "false");
properties.put("mail.smtp.starttls.enable", "true");
// properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.host", host);
// properties.put("mail.smtp.port", "25");
/*
* properties.put("mail.smtp.host",host);
* properties.put("mail.smtp.auth", "false");
*/
Session session = Session.getInstance(properties, null);
session.setDebug(true);
// Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.saveChanges();
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Test mail");
// message.setContent("", host);
message.setText("This is test mail.");
// send the message
Transport.send(message);
System.out.println("message sent successfully...");
} catch (MessagingException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "mail.sap.corp", port 25, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: mail.sap.corp, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at com.emailer.main.SendEmail.sendEmail(SendEmail.java:61)
at com.emailer.main.SendEmail.main(SendEmail.java:26)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 8 more
Hi Santhosh,
"Could not connect to SMTP host: mail.sap.corp, port: 25"
Sound like firewall or any ohther network failure.
regards,
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.