mail using java from iitb network

58 views
Skip to first unread message

Manish Punjabi

unread,
Jun 24, 2014, 7:52:41 AM6/24/14
to wncc...@googlegroups.com
I am able to use gmail smtp server to send emai [using java mail] from external network. However, within iit network, I am trying to use smpt-auth.iitb.ac.in and it fails to send mails.



 The following is the code.

final String username = "ldapid";
final String password = "ldappasswd";
 
Properties props = new Properties();
props.put("mail.smtp.host", "smtp-auth.iitb.ac.in");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.ehlo", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ehlo", "true");
props.put("mail.smtp.auth", "true");
        props.put("mail.debug", "true");
 
Session session = Session.getInstance(props,
 new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
 });
 
try {
 
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("lda...@iitb.ac.in"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("rece...@gmail.com"));
message.setSubject("Testing Mail");
message.setText("test email !");
 
Transport.send(message);

 
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}

I get the following exception:

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Dilawar Singh

unread,
Jun 24, 2014, 10:25:41 AM6/24/14
to wncc_iitb

Check how to accept certificates from SMTP server.

dilawar

--
--
The website for the club is http://wncc-iitb.org/
To post to this group, send email to wncc...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Web and Coding Club IIT Bombay" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wncc_iitb+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Saket Choudhary

unread,
Jun 24, 2014, 10:29:06 AM6/24/14
to wncc...@googlegroups.com
You might want to change the auth_type.
smtp.esmtp_features["auth"] = "LOGIN PLAIN"

There should be a java equivalent for this

Saket


--

Manish Punjabi

unread,
Jun 25, 2014, 8:52:58 AM6/25/14
to wncc...@googlegroups.com
@Saket : I tried login plain but still the same exception.


javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:671)
at sun.security.ssl.InputRecord.read(InputRecord.java:504)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at InstallCert.main(InstallCert.java:63)
Could not obtain server certificate chain


On Tuesday, June 24, 2014 5:22:41 PM UTC+5:30, Manish Punjabi wrote:
I am able to use gmail smtp server to send emai [using java mail] from external network. However, within iit network, I am trying to use smpt-auth.iitb.ac.in and it fails to send mails.



 The following is the code.

final String username = "ldapid";
final String password = "ldappasswd";
 
Properties props = new Properties();
props.put("mail.smtp.host", "smtp-auth.iitb.ac.in");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.ehlo", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ehlo", "true");
props.put("mail.smtp.auth", "true");
        props.put("mail.debug", "true");
 
Session session = Session.getInstance(props,
 new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
 });
 
try {
 
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("ldapid@iitb.ac.in"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("recepien...@gmail.com"));
message.setSubject("Testing Mail");
message.setText("test email !");
 
Transport.send(message);

 
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
Reply all
Reply to author
Forward
0 new messages