Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sending mail with and without authentication --URGENT

843834Jul 2 2008 — edited Jul 2 2008
Good morning to all..

i am facing problem in sending mails. My application sends mail without authentication .And the code is


//create properties and get the default Session
Properties objProperties = System.getProperties();
objProperties.put("mail.smtp.host", strMailHost);

//Create a new session
Session objSession = Session.getInstance(objProperties, null);

//create a message
MimeMessage objMessage = new MimeMessage(objSession);

//create the Multipart
Multipart objMultipart = new MimeMultipart();

//Set Message Date, Sender, Recepients(To/CC/BCC) And Subject
createMessage(objMessage, argobjUdtMail);

//Create Message Subject, Message Body and Attach file
createContent(objMessage, objMultipart, argobjUdtMail);

Transport transport = objSession.getTransport(MAILPROTOCOL);

// Connect
transport.connect(strMailHost, strUserId, strPassword);
transport.send(objMessage);

And now as per the customer requirement i need to take care of sending mail with password authenticaton. in one line my code should work for both with or without password authentication , like if password authentication is not enabled ,then should send mail without authenticating and if password authentication is enabled should send mail with authentication.
if i add
objProperties.put("mail.smtp.auth","true"); i get error in sending mails with the server where password authentication is not enabled.

How do i modify my code to work for both , with or without password authentication.

if anyone can give any pointer , will be a great help .

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 30 2008
Added on Jul 2 2008
3 comments
649 views