Envoi email

medissamjava Messages postés 28 Date d'inscription samedi 19 avril 2008 Statut Membre Dernière intervention 12 mai 2010 - 12 mai 2010 à 17:47
mamytawa Messages postés 2 Date d'inscription samedi 23 juillet 2011 Statut Membre Dernière intervention 11 octobre 2011 - 11 oct. 2011 à 16:24
slt tout le monde.
je veux crées une application qui permet d'envoyer un email mais j'ai reçu le message d'erreur suivant:
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
  nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1378)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:399)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at project1.YahooTest.sendSSLMessage(YahooTest.java:73)
at project1.YahooTest.main(YahooTest.java:30)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:520)
at java.net.Socket.connect(Socket.java:470)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:220)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:176)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1346)
... 8 more
Process exited with exit code 1.


mon code est le suivant:

import java.security.Security;

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 GmailTest {
 
    private static final String SMTP_HOST_NAME = "smtp.gmail.com";
    private static final String SMTP_PORT = "465";
    private static final String emailMsgTxt = "Test Message Contents";
    private static final String emailSubjectTxt = "A test from gmail";
    private static final String emailFromAddress = "user@gmail.com";
    private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
    private static final String[] sendTo = {"user@gmail.com"};
    
    public static void main(String args[]) throws Exception {
 
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
 
        new GmailTest ().sendSSLMessage(sendTo, emailSubjectTxt, emailMsgTxt, emailFromAddress);
        System.out.println("Sucessfully Sent mail to All Users");
    }
 
    public void sendSSLMessage(String recipients[], String subject,
            String message, String from) throws MessagingException {
        boolean debug = true;
 
        Properties props = new Properties();
        props.put("mail.transport.protocol", "smtp");

        props.put("mail.smtp.host", SMTP_HOST_NAME);
        props.put("mail.smtp.auth", "true");
        props.put("mail.debug", "true");
        props.put("mail.smtp.port", SMTP_PORT);
        props.put("mail.smtp.socketFactory.port", SMTP_PORT);
        props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
//       props.put("mail.smtp.socketFactory.fallback", "false");
//        props.put("mail.smtp.starttls.enable","true");
        
        Session session = Session.getDefaultInstance(props,
                new javax.mail.Authenticator() {
 
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("user@gmail.com", "xxxx");
                    }
                });
 
        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);
 
        // Setting the Subject and Content Type
        msg.setSubject(subject);
        msg.setContent(message, "text/plain");
        Transport.send(msg);
    }
}





SVP aidez moi

3 réponses

dalal1985 Messages postés 1 Date d'inscription vendredi 9 mai 2008 Statut Membre Dernière intervention 17 juin 2010
17 juin 2010 à 23:41
bonsoir essaie avec : private static final String SMTP_HOST_NAME = "pop.gmail.com"; ça devrai marcher bonne chance
0
mamytawa Messages postés 2 Date d'inscription samedi 23 juillet 2011 Statut Membre Dernière intervention 11 octobre 2011
11 oct. 2011 à 15:53
bonjour j'ai un probleme avec mon programme javamail quand je configure mon serveur en utilsant le service pack3 de xp pro je reuisie a envoyé les message seulement a mon poste.quand il s'agit d'une adresse mail gmail ou yahoo par exemple je recoit l'erreur suivante"unable to relay to monadresse@yahoo.fr" aider moi
0
mamytawa Messages postés 2 Date d'inscription samedi 23 juillet 2011 Statut Membre Dernière intervention 11 octobre 2011
11 oct. 2011 à 16:24
bonjour j'ai un probleme avec mon programme javamail quand je configure mon serveur en utilsant le service pack3 de xp pro je reuisie a envoyé les message seulement a mon poste.quand il s'agit d'une adresse mail gmail ou yahoo par exemple je recoit l'erreur suivante"unable to relay to monadresse@yahoo.fr" aider moi j'utilise la connection wifi pour acceder a internet est ce que je doit forcement avoir acheter un acces internet(je veut dire faut d'il obligatiorement un service intranet
voila le code

import java.util.Properties;

import javax.mail.Session;
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import javax.mail.Transport;

import javax.mail.internet.AddressException;
import javax.mail.NoSuchProviderException;
import javax.mail.MessagingException;

public class SendTextMessage {
public static void main(String[] args) {
try {
Properties props = new Properties();
// props.setProperty("mail.from", "contact@chicoree.fr");
Session session = Session.getInstance(props);
session.setDebug(true);
Message message = new MimeMessage(session);
InternetAddress recipient = new InternetAddress("tawahortense@yahoo.fr");
message.setRecipient(Message.RecipientType.TO, recipient);
message.setSubject("Hello JavaMail");
message.setText("JavaMail vous dit bonjour!");

Transport.send(message);
}
catch(NoSuchProviderException e) {
System.err.println("Pas de transport disponible pour ce protocole");
System.err.println(e);
}
catch(AddressException e) {
System.err.println("Adresse invalide");
System.err.println(e);
}
catch(MessagingException e) {
System.err.println("Erreur dans le message");
e.printStackTrace();
System.err.println(e);
}
}
}
0
Rejoignez-nous