• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending Mail via SMTP server

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I m having problem with sending mail with POP3 server, the funny thing is when I try to run the same block of code via public static void main() it runs fine, but when it is ran through a batch flow throws error @
transport.connect(hostName, userName, password);

saying....

DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "Smtp.mail.apac.microsoftonline.com", port 25, isSSL false

javax.mail.MessagingException: Could not connect to SMTP host: Smtp.mail.apac.microsoftonline.com, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect

One more thing to notice here is even though I set POP3 port to ["mail.smtp.port", "587"] in the session properties, its using port number as 25,
and when I explicitly ask it to connect via port over 587

i.e transport.connect(hostName, 587, userName, password);

it throws exception as...

DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "Smtp.mail.apac.microsoftonline.com", port 587, isSSL false
220 smtp.mail.apac.microsoftonline.com Microsoft ESMTP MAIL Service ready at Tue, 14 Jun 2011 03:07:08 -0700
DEBUG SMTP: connected to host "Smtp.mail.apac.microsoftonline.com", port: 587

javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client

I have no idea for what and why its causing so

Please help me out,
thanks and Regards
Mithun


 
Mithun Pissay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and one more thing for you info,

Though i m setting "mail.smtp.auth","true" in session properties the SMTP DEBUG is showing as

DEBUG SMTP: useEhlo true, useAuth false

!!!
 
Rancher
Posts: 43081
77
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't send email via pop3; you need to use an SMTP server.
 
Mithun Pissay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ulf, sorry for confusion indeed mail is sent over SMTP protocol, and have used SMTP for sending mail... and if you had noticed my post i m using Smtp.mail.apac.microsoftonline.com host as well.
I apologize in heat of the situation and deadline my Post header was misleading...
but the issue is still open please provide your insight on the problem.

And gonna change the Post Subject/header so others wont get mislead.

Thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you providing the authentication details?
 
Mithun Pissay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf, FYI
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.host", "Smtp.mail.apac.microsoftonline.com");
props.setProperty("mail.smtp.port", "587");
props.setProperty("mail.smtp.auth","true");
props.put("mail.smtp.starttls.enable","true");
...

Session mailSession = Session.getDefaultInstance(props, null);
SMTPTransport transport = (SMTPTransport) mailSession.getTransport("smtp");
transport.connect("Smtp.mail.apac.microsoftonline.com", userEmailId, userEmailPwd);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));

Getting java mail Session with passing authenticator as null later part in the code SMTPTransport would connect and authenticate along with userEmailId and password.

Further, for your information, after you brought up authentication perspective, i tried getting session with passing an authenticator object with userEmailId and password set in the auth object, And the result was same with above test case (referring to initial post) execution.
 
Mithun Pissay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, thanks for your time and brain stroming over my posted issue,

I found out the issue was with not using System properties (i.e System.getProperties() ), even though I was setting designated port (587) into java.util.Properties it was taking default port 25 for sending mail via SMTP as it was reading from the system properties for getting port and it had not been set while getting mail Session project.

But one thing is still bugging me is why with all the session properties set into java.util.Properties object for getting mail Session was working when called independently and not working when the batch flow took over the call to send mail,
and let me tell you i was not using properties object got from System.getProperties() call before any where. is it the API designed so to read from System.getProperties() properties ? I am using standard mail.jar i.e java extended API

If any of you guys know what exactly the reason please do reply to this post.

Thank you again all of you guys for supporting
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic