Results 1 to 6 of 6
  1. #1
    cyberaa is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default JAVA MAIL Connection Time Out ...

    Hey, im not really new to java, but i never worked with this library before, and after i try different ways, i always get connection timed out ...
    Can you see anything missing from my code?


    Java Code:
    import java.util.Properties;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    
    public class Sendfile
    {
          public static void main(String[] args) {
                Properties props = new Properties();
                /** Parâmetros de conexão com servidor Hotmail */
                props.put("mail.transport.protocol", "smtp");
                props.put("mail.smtp.host", "smtp.gmail.com");
                props.put("mail.smtp.socketFactory.port", "587");
                props.put("mail.smtp.socketFactory.fallback", "false");
                props.put("mail.smtp.starttls.enable", "true");
                props.put("mail.smtp.auth", "true");
                props.put("mail.smtp.port", "587");
    
                Session session = Session.getDefaultInstance(props,
                            new javax.mail.Authenticator() {
                                 protected PasswordAuthentication getPasswordAuthentication() 
                                 {
                                       return new PasswordAuthentication("yourmail", "password");
                                 }
                            });
                /** Ativa Debug para sessão */
                session.setDebug(true);
                try {
    
                      Message message = new MimeMessage(session);
                      message.setFrom(new InternetAddress("frommail")); //Remetente
    
                      message.setRecipients(Message.RecipientType.TO, 
                                        InternetAddress.parse("tomail")); //Destinatário(s)
                      message.setSubject("Enviando email com JavaMail");//Assunto
                      message.setText("Enviei este email utilizando JavaMail com minha conta Hotmail!");
                      /**Método para enviar a mensagem criada*/
                      Transport.send(message);
                      System.out.println("Feito!!!");
                 } catch (MessagingException e) {
                      throw new RuntimeException(e);
                }
          }
    }
    Every time that i try to send an email i get connection time out ... Can someone find whats missing in this code?
    thanks ...
    Last edited by cyberaa; 02-23-2011 at 01:59 AM.

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    You should also use the SSLSocketFactory settings or it may give a "Must issue a STARTTLS command first" error.

    If you are getting connection time out, try out for other port. May be use 465 instead of 587.

    Hope that helps,

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    cyberaa is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Hey,
    i added the SSLFACTORYSocket and tried both ports and now it works
    Thanks alot :P

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    6

    Wink

    You are welcome... :D

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  5. #5
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default Please reply as i did not understand ...

    Could you please tell me little elaborative that how you have added the new socket and fix this issue?

  6. #6
    ab4abhisek is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default

    Hi cyberra,could you please post the final running code here?

Similar Threads

  1. Replies: 1
    Last Post: 04-04-2014, 04:25 PM
  2. Facing problem in making connection to mail server
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 01-22-2010, 07:27 PM
  3. Replies: 2
    Last Post: 06-04-2009, 02:42 PM
  4. Replies: 2
    Last Post: 05-05-2008, 07:01 AM
  5. Calculating the DB connection time
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •