cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using Javax.Mail API

former_member225041
Participant
0 Kudos

Hi Experts,

I am using Javax.mail API to send an email through java application. But i am facing an issue when i am deploying the java application in SAP WAS.

I have assigned values in SMTP Host ,Port, and InternetAddress and deployed to WAS. But when i deploy this java class again in WAS with changing the values for SMTP Host ,Port and InternetAddress and putting in Properties object ,its always picking the values set at first time.

Can anyone tell me whats wrong with following code .

Properties prpt = new Properties();

if (host == null)

{

host=token[0];

}

prpt.put("mail.smtp.host",host);

prpt.put("mail.smtp.sendpartial", "true");

if (port == null)

{

port=token[1];

}

prpt.put("mail.smtp.port", port);

Session session1=Session.getDefaultInstance(prpt, null);

MimeMessage message=new MimeMessage(session1);

message.setFrom(new InternetAddress(emailId"));

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The problem is caused due to the way you get the Session instance: By using the method getDefaultInstance your property values don't matter once the method was executed once. Just try replacing in your code the call to getDefaultInstance with the following:


// Session session1=Session.getDefaultInstance(prpt, null);
// Replace with
Session session1=Session.getInstance(prpt, null);

Cheers, harald

Answers (0)