De Transport.send(message) ne fonctionne pas dans le code ci-dessous.. netbeans se coince lors de l'exécution de la partie. il n'a pas donné suite, d'autres personnes.. il se bloque toujours

J'ai essayé d'écrire un code pour envoyer des e-mail à l'aide de Java. Mais ce code ne fonctionne pas. Lorsque le code est exécuté, il est coincé au transport.send(message). Il reste là pour toujours. Aussi, je ne suis pas sûr si le reste du code est correct ou pas.

  //first from, to, subject, & text values are set
    public class SendMail {
    private String from;
    private String to;
    private String subject;
    private String text;


    public SendMail(String from, String to, String subject, String text){
        this.from = from;
        this.to = to;
        this.subject = subject;
        this.text = text;
    }

    //send method is called in the end 
    public void send(){

        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "465");

        Session mailSession = Session.getDefaultInstance(props);
        Message simpleMessage = new MimeMessage(mailSession);

        InternetAddress fromAddress = null;
        InternetAddress toAddress = null;
        try {
            fromAddress = new InternetAddress(from);
            toAddress = new InternetAddress(to);
        } catch (AddressException e) {
            //TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            simpleMessage.setFrom(fromAddress);
            simpleMessage.setRecipient(RecipientType.TO, toAddress);
            simpleMessage.setSubject(subject);
                    simpleMessage.setText(text);
            Transport.send(simpleMessage);  //this is where code hangs     
        } catch (MessagingException e) {
            //TODO Auto-generated catch block
            e.printStackTrace();
        }       
    }
}

OriginalL'auteur user1155707 | 2012-01-18