IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Java Discussion :

Erreur javaMail : Could not connect to SMTP host


Sujet :

API standards et tierces Java

  1. #1
    Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2010
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2010
    Messages : 38
    Points : 42
    Points
    42
    Par défaut Erreur javaMail : Could not connect to SMTP host
    Bonjour,
    j'ai utiliser la classe suivante pour envoyer des email:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
     
    import email.Mailer;
    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;
    import javax.mail.internet.MimeMessage.RecipientType;
     
    public class MailWithPasswordAuthentication {
    	public static void main(String[] args) throws MessagingException {
    		new MailWithPasswordAuthentication().run();
     
    	}
     
    	private void run() throws MessagingException {
    		Message message = new MimeMessage(getSession());
     
     
    		message.addRecipient(RecipientType.TO, new InternetAddress("myEmail@gmail.com"));
    		message.addFrom(new InternetAddress[] { new InternetAddress("myEmail@gmail.com") });
     
    		message.setSubject("the subject");
    		message.setContent("the body", "text/plain");
     
    		Transport.send(message);
     
     
     
    	}
     
    	private  Session getSession() {
    		Authenticator authenticator = new Authenticator();
                    //System.out.println("Start ... ");
     
    		Properties properties = new Properties();
    		properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName());
    		properties.setProperty("mail.smtp.auth", "true");
                  // properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                  //  properties.setProperty("mail.smtp.socketFactory.fallback", "javax.net.ssl.SSLSocketFactory");
                    properties.setProperty("mail.smtp.starttls.enable", "false");
     
    		properties.setProperty("mail.smtp.host", "smtp.offshorevalley.net");
    		properties.setProperty("mail.smtp.port", "25");
     
     
    		return Session.getInstance(properties, authenticator);
    	}
     
    	private class Authenticator extends javax.mail.Authenticator {
    		private PasswordAuthentication authentication;
     
    		public Authenticator() {
    			String username = "myEmail@gmail.comt";
    			String password = "myPassWord";
    			authentication = new PasswordAuthentication(username, password);
    		}
     
    		protected PasswordAuthentication getPasswordAuthentication() {
    			return authentication;
    		}
    	}
    }

    le problème est le suivant;
    le code ca marche bien dans un premier temps et après quelque utilisation je rencontre l'erreur suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.offshorevalley.net, port: 25;
      nested exception is:
    	java.net.ConnectException: Connection timed out: connect
    	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    	at javax.mail.Service.connect(Service.java:317)
    	at javax.mail.Service.connect(Service.java:176)
    	at javax.mail.Service.connect(Service.java:125)
    	at javax.mail.Transport.send0(Transport.java:194)
    	at javax.mail.Transport.send(Transport.java:124)
    	at Test.MailWithPasswordAuthentication.run(MailWithPasswordAuthentication.java:31)
    	at Test.MailWithPasswordAuthentication.main(MailWithPasswordAuthentication.java:17)
    Caused by: java.net.ConnectException: Connection timed out: connect
    	at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
    	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    	at java.net.Socket.connect(Socket.java:579)
    	at java.net.Socket.connect(Socket.java:528)
    	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
    	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
    	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    	... 8 more
    Java Result: 1
    j'ai essayer avec plusieurs code et toujours les mêmes résultat ( tout ça marche bien dans un premier temps,et en suite l'erreur

    ya quelqu’un qui peut me dire pourquoi cette erreur ??

    Merci en avance !!

  2. #2
    Membre du Club Avatar de tonymx15
    Homme Profil pro
    Intégrateur Web
    Inscrit en
    Juin 2010
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cantal (Auvergne)

    Informations professionnelles :
    Activité : Intégrateur Web

    Informations forums :
    Inscription : Juin 2010
    Messages : 140
    Points : 53
    Points
    53
    Par défaut
    J'avais aussi la même erreur avec JavaMail, j'ai trouvé une solution sur un site qui marche très bien...

    Lien : http://www.mkyong.com/java/javamail-...-smtp-example/

    Prends la version SSL pas TLS

  3. #3
    Membre du Club
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2010
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mai 2010
    Messages : 38
    Points : 42
    Points
    42
    Par défaut
    Merci pour ta réponse ...
    je vais essayer avec votre solution proposée

Discussions similaires

  1. [Javamail] Erreur "Could not connect to SMTP host"
    Par cabistos dans le forum API standards et tierces
    Réponses: 5
    Dernier message: 21/11/2014, 13h18
  2. Réponses: 1
    Dernier message: 03/05/2013, 16h48
  3. Réponses: 2
    Dernier message: 21/09/2012, 17h21
  4. PHPMailer : Could not connect to SMTP host
    Par judy-brainy dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 2
    Dernier message: 17/07/2010, 03h20
  5. [Javamail] could not connect to smtp host
    Par metwa dans le forum API standards et tierces
    Réponses: 14
    Dernier message: 06/06/2009, 12h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo