In my application when a user registers, after a successful registration the user is sent an email containing a link for the activation of account. This application runs quite well on my local machine. But after uploading it to the server, the user completes his registration successfully, but when it comes to sending an email to the user, the following exception is thrown. Can somebody please help me and tell me whats wrong going on here.
Code:
------------------
Properties props = new Properties();
props.put(KEY1, SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port","25");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the From and To address
InternetAddress addressFrom = new InternetAddress(FROM);
msg.setFrom(addressFrom);
// gets recipients email address
InternetAddress addressTo = new InternetAddress(emailTo);
msg.setRecipient(Message.RecipientType.TO, addressTo);
// Set the Subject
msg.setSubject(subject);
msg.setSentDate(new Date());
// gets file contents as a
string String filecontents = fileContents(textfilename );
//Set the Content Type
msg.setContent(filecontents, "text/html");
// send the message
Transport.send(msg);
-------------------------------------------------------------
Exception:
------------
javax.mail.MessagingException: Could not connect to SMTP host: mail.myserver.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1213)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:311)
at javax.mail.Service.connect(Service.java:255)
at javax.mail.Service.connect(Service.java:134)
at javax.mail.Service.connect(Service.java:86)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:144)
at javax.mail.Transport.send0(Transport.java:150)........
..................
..................
..................
Thanks.