Connecting to SMTP behind firewall
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ujjwala_Kadam
Posted On:   Thursday, October 11, 2007 07:47 AM

I am trying to use JavaMail for sending emails from my standalone application running on a JBoss server. Following is the code snippet. When I execute this code, I get the error saying connection timed out. My mail server is behind firewall however port 25 is open and I can very well telnet the port and get response. This code works fine on my local email server. Am I missing something in this? Thanks in advance for your help. public boolean postMail( String recipients[ ], String subject, String message , String from) throws MessagingException { boolean debug = true; boolean success = false; try{ //Set the host smtp address Properti   More>>

I am trying to use JavaMail for sending emails from my standalone application running on a JBoss server.
Following is the code snippet.
When I execute this code, I get the error saying connection timed out.
My mail server is behind firewall however port 25 is open and I can very well telnet the port and get response.
This code works fine on my local email server.
Am I missing something in this?
Thanks in advance for your help.


			
public boolean postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = true;
boolean success = false;

try{
//Set the host smtp address
Properties props = System.getProperties();
props.put("mail.host", SMTP_HOST_NAME);
props.put("mail.smtp.port", SMTP_PORT);
Session session = javax.mail.Session.getInstance(props, null);
session.setDebug(debug);
Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
msg.setContent(message, "text/html");
Transport.send(msg);
success = true;
}catch(MessagingException me){
success = false;
me.printStackTrace();
}
return success;
}


   <<Less

Re: Connecting to SMTP behind firewall

Posted By:   Robert_Lybarger  
Posted On:   Thursday, October 11, 2007 09:10 AM

Complete shot in the dark: is the firewall configured to only allow a connection *from* a specific port? And if so, do you have a way to configure that in the javamail library? (I've not really used it.)
About | Sitemap | Contact