Results 1 to 12 of 12
Thread: javamail, Connection timed out
- 04-04-2010, 06:33 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0
javamail, Connection timed out
hi,
I am trying to send email, I think something blocks it.
I keep getting this error :
it seems like it is a firewall problem, but i turned off my antivirus and firewall. when I try to connect from cmd (telnet smtp.live.com 25) it cant connect either. I tried to unblock port 25 but I couldnt make it either, I put exception to windows firewall(it is already turned off) it still cant connect thru that port.Java Code:Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.live.com, port: 25; nested exception is: java.net.ConnectException: Connection timed out: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706) ...
but when i type telnet smtp.live.com 587 to command promt, it connects..
how do I overcome this problem? or how do I connect over port 587 in java?
here is my code:
thanks..Java Code:public class SendMailUsingAuthentication { private static final String SMTP_HOST_NAME = "smtp.live.com"; private static final String SMTP_AUTH_USER = "asd@hotmail.com"; private static final String SMTP_AUTH_PWD = "asdasd"; private static final String emailMsgTxt = "msg text"; private static final String emailSubjectTxt = "subject txt"; private static final String emailFromAddress = "asd@yahoo.com"; // Add List of Email address to who email needs to be sent to private static final String[] emailList = {"asd@hotmail.com", "qwe@hotmail.com"}; public static void main(String args[]) throws Exception { SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication(); smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress); System.out.println("Sucessfully Sent mail to All Users"); } public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException { boolean debug = false; //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.auth", "true"); 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); 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); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/plain"); Transport.send(msg); } /** * SimpleAuthenticator is used to do simple authentication * when the SMTP server requires it. */ private class SMTPAuthenticator extends javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { String username = SMTP_AUTH_USER; String password = SMTP_AUTH_PWD; return new PasswordAuthentication(username, password); } } }
- 04-04-2010, 07:37 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Changing the port to use is easy:
If you really want to know what's going on between your client and the smtp server, do this:Java Code:String port= "587"; ... Properties props = System.getProperties(); props.put("mail.smtp.port", port);
kind regards,Java Code:session.setDebug(true);
Jos
- 04-05-2010, 05:47 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0
thank you, it worked for that error.. :) this is the another error I got..
when i connected to smtp thru command prompt, whatever I type, it used to give me the same error..Java Code:Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829) at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886) at javax.mail.Transport.send0(Transport.java:191) at javax.mail.Transport.send(Transport.java:120) at SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:100) at SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:61) Java Result: 1
i think connecting to the smtp is ok.. but i can't send the mail, is it because i don't use proper command? :confused:
i connected to smtp thru command prompt, when i typed "STARTTLS" and press enter, it says "Send hello first". what does it mean?
thank you again..Last edited by OmerHalit; 04-05-2010 at 06:01 AM.
- 04-06-2010, 05:52 PM #4
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
I'm sure it didn't say send Hello first, but rather send HELO first right?
There are two things I remember from when I worked with this...
Try adding another property:
also I remember creating an instance of Transport to send the message, something like thisJava Code:props.put("mail.smtp.ehlo","true");
Hope this helps.Java Code:Transport transport = session.getTransport("smtp"); transport.connect();//You could specify the Server Address, User Name and Password when connecting but I don't think you need it transport.sendMessage(msg, msg.getAllRecipients()); transport.close();
- 04-06-2010, 06:06 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0

it really says that..
ok, i will try what you said.. give me a while to try..
Thanks..
- 04-06-2010, 06:14 PM #6
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0
I tried, it didn't work.. :(
what else could be?
- 04-06-2010, 06:48 PM #7
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
I never tried connecting to a hotmail account. Let me create one and attempt it.
- 04-06-2010, 06:52 PM #8
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0
ok, here is the last looking of my code
...
msg.setRecipients(Message.RecipientType.TO, addressTo);
//everything is same until here
//here was changed according to StormyWaters' suggestion
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport transport = session.getTransport("smtp");
transport.connect();
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
//Transport.send(msg);
I get no error until this line : transport.sendMessage(msg, msg.getAllRecipients());
means that, i can connect, but i cannot send the mail.. :( any help??
- 04-06-2010, 07:14 PM #9
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Forgot a property, try adding this
Java Code:props.put("mail.smtp.starttls.enable","true");
- 04-06-2010, 07:16 PM #10
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0
You are great...!!!
Thanks, it worked.. :)Last edited by OmerHalit; 04-06-2010 at 07:19 PM.
- 04-11-2010, 10:39 AM #11
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
how to receive hotmail
how to receive hotmail? when I user store to receive the mail,always to remind me Connect failed;
- 04-12-2010, 07:02 AM #12
Member
- Join Date
- Mar 2010
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
Connection Timed Out
By sukatoa in forum NetworkingReplies: 2Last Post: 10-27-2009, 03:20 PM -
connection timed out in my java code
By santhosh_el in forum AWT / SwingReplies: 4Last Post: 10-22-2009, 12:24 PM -
solution for connection timed out
By santhosh_el in forum NetworkingReplies: 0Last Post: 10-03-2009, 07:55 AM -
i am getting connection timed out
By santhosh_el in forum NetworkingReplies: 1Last Post: 08-25-2009, 06:57 AM -
using Java to access a secure webpage, Exception occurred: Connection timed out
By toby in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 08-07-2007, 06:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks