cancel
Showing results for 
Search instead for 
Did you mean: 

Mail sending exception

Former Member
0 Kudos

Hi All,

I am developing a Contact Us form. The application is giving me the foll. exception

javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Unknown SMTP host: mail.exchange.com; nested exception is: java.net.UnknownHostException: mail.exchange.com

My code is as follows:

Properties properties = new Properties();

String SMTPIPAddress = "smtpipaddress";

String SMTPAddress = "smtpaddress";

String mailId = "mymailid@domain.com";

Session session;

Provider p;

properties = System.getProperties();

properties.put("SMTPAddress ", "SMTPIPAddress");

session = Session.getDefaultInstance(properties, null);

Message message = new MimeMessage(session);

try{

message.setFrom(new InternetAddress(mailId));

message.addRecipient(Message.RecipientType.TO,

new InternetAddress(mailId));

message.setSubject("Conference");

message.setText("Hello");

Transport.send(message);

}catch (AddressException ade) {

wdComponentAPI.getMessageManager().raiseException(ade.toString(),false);

}catch(MessagingException msge){

wdComponentAPI.getMessageManager().raiseException("MessagingException "+msge.toString(),true);

}catch(Exception e){

wdComponentAPI.getMessageManager().raiseException("Exception "+e.toString(),true);

}

Please let me know what is wrong.

Regards

Nikhil Bansal

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Nikhil

Check for ur SMTP ip address..

Regards

khushboo

Former Member
0 Kudos

Hi Nikhil,

I think you are missing the following in your shared Reference.Pl add this and give a try:

<property name="PrivateSharingReference" value="SAPJ2EE::library:mail"/>

Thanks,

Former Member
0 Kudos

Nikhil,

Code seems to be good.

Please check wheather port for the same is opened or not.

Usaully Port has to be configured to send a mail.

regards

Anil

Former Member
0 Kudos

Hi Anil,

Do I have to add the port number in my code.

Also do I have to give the entry for smtp in Java Mail Client in Visual Admin

J2EE Visual Administrator -> Server -> Java mail client

As of now this entry has localhost as the parameter.

Regards

Nikhil Bansal

abhijeet_mukkawar
Active Contributor
0 Kudos

Nikhil,

exactly in Java Mail Client you need to add IP address of client

SMTP should have the IP of your mail client.

regards

Former Member
0 Kudos

Hi Abhijeet,

Thanks for the reply.

I have given the IP address of SMTP address in Java Mail Client in Visual Admin.

However, I am getting the foll. exception

MessagingException javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect

Has it got something to do with the port being opened for SMTP host.

Please let me know.

Regards

Nikhil

Former Member
0 Kudos

Nikhil,

Address here is address of SMTP server within your network.

Try to set IP address or name of your mail server (that you are using for own mail) and check again.

VS

Former Member
0 Kudos

Nikhil,

As mentioned earlier please open the port number.

Can you please ping and check wheather you are able to connect to server or not.

to check wheather port is opened for the ipaddress

go ro command prompt and then type following

c:/telnet <ipaddress> <portnumber>

regards

Anil

Former Member
0 Kudos

Hi,

I am also getting the same error:

javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Could not connect to SMTP host: 10.236.133.250, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect

I configured in VA-> JAVA MAIL->SMTP as the SMTP IP

I am also able to ping thru' telnet.

Where do I need to configure port ?

Regards,

Poonam

Former Member
0 Kudos

Nikhil,

Code seems to be good.

Please check wheather port for the same is opened or not.

Usaully Port has to be configured to send a mail.

regards

Anil