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 :

[javamail] erreur d'execution [FAQ]


Sujet :

API standards et tierces Java

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut [javamail] erreur d'execution
    salut
    moi j'essayé la JAVAMAIL mais ca marche pas j'essai d'utiliser le server de mon entreprise mais comment renseigner les paramtres de connexion
    ex : mot de passe du compte

    de plus j'ai cette erreur:
    • java.lang.NoClassDefFoundError: javax/activation/DataSource
      at cba.EnvoiMail.Envoi(EnvoiMail.java:32)
      at cba.EnvoiMail.main(EnvoiMail.java:17)

    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
     
    package mail ; 
     
    import javax.mail.*; 
    import javax.swing.JFrame; 
    import javax.mail.internet.*; 
    import java.util.*; 
     
    public class EnvoiMail extends JFrame { 
       private final static String MAILER_VERSION = "Java"; 
     
       public EnvoiMail() { 
       } 
     
       public static void main(String[] args) { 
          EnvoiMail Mail = new EnvoiMail(); 
          Mail.setVisible(false) ; 
          if(Mail.Envoi("194.79.150.98",true)) 
             System.out.println("Mail ok") ; 
          else 
             System.out.println("Mail nok") ; 
       } 
     
       public boolean Envoi(String serveur, boolean debug) 
       { 
           boolean result = false; 
           try { 
               Properties prop = System.getProperties(); 
               prop.put("mail.mcd.mc", serveur); 
               //prop.put("mail.smtp.host", serveur); 
               Session session = Session.getDefaultInstance(prop,null); 
               Message message = new MimeMessage(session); 
               message.setFrom(new InternetAddress("dedouard@dbb.fr")); 
               InternetAddress[] internetAddresses = new InternetAddress[1]; 
               internetAddresses[0] = new InternetAddress("dedouard@dbb.fr"); 
               message.setRecipients(Message.RecipientType.TO,internetAddresses); 
               message.setSubject("Test de l'envoi d'un message"); 
               message.setText("Hello Braim, tu t'envoi ce mail tout seul "); 
               message.setHeader("X-Mailer", MAILER_VERSION); 
               message.setSentDate(new Date()); 
               session.setDebug(debug); 
               Transport.send(message); 
               result = true; 
           } catch (AddressException e) { 
               e.printStackTrace(); 
           } catch (MessagingException e) { 
               e.printStackTrace(); 
           } 
           return result; 
       } 
    }

  2. #2
    Membre habitué

    Profil pro
    Inscrit en
    Février 2003
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2003
    Messages : 119
    Points : 136
    Points
    136
    Par défaut
    Hello,


    Scusez du retard mais y'a quand même des jours ou je bosse.

    Voila, cet exemple de JavaMail fonctionne.

    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
     
    import javax.mail.*; 
    import javax.swing.JFrame; 
    import javax.mail.internet.*; 
    import java.util.*; 
     
     
    /*
     * Created on 04-déc.-2003
     *
     * To change the template for this generated file go to
     * Window - Preferences - Java - Code Generation - Code and Comments
     */
     
    /**
     * @author Braim
     *
     * To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Generation - Code and Comments
     */
    public class SendMail 
    {     
        public static void main(String[] args) 
        {
     
            String destinataire = "milou@hotmail.com";
            String expediteur = "tintin@herge.com";
            String serveurSMTP = "XXX.XXX.XXX.XXX";  
     
            Properties props = new Properties();
            props.put("mail.smtp.host", serveurSMTP);
     
            Session session = Session.getInstance(props, null);       
            try 
            {
                Message msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(expediteur));
                InternetAddress[] address = {new InternetAddress(destinataire)};
                msg.setRecipients(Message.RecipientType.TO, address);
                msg.setSubject("Hello le monde mondial des terriens");
                msg.setSentDate(new Date());
                msg.setText("Hello Braim. Tu recois ce message par toi même :p");
     
                Transport.send(msg);
            } 
            catch (MessagingException mex) 
            {
                System.out.println("\nErruer");
                mex.printStackTrace();
            }
        }  
    }
    Pour ton problème de
    java.lang.NoClassDefFoundError: javax/activation/DataSource
    C'est normal. Je suis sur que tu n'a pas télécharger JavaBean Activation FrameWork depuis le site de Sun ??
    Il y a dedans un fichier activation.jar qui doit être dans le classpath
    Dans le code que je viens de poster, faut juste changer les 3 paramètres au début du main


    [edit]
    J'ai oublié de retirer le SMTP et mon mail de ma boite
    [/edit]

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut
    j'ai l'erreur suivante :
    Exception in thread "main" java.lang.NoClassDefFoundError :
    javax/mail/MessagingException

    croit tu que c'est parce ce que j'ai sendmail sur mon poste (linux)
    et que j'ai donc mit comme adresse 127.0.0.1

  4. #4
    Membre habitué

    Profil pro
    Inscrit en
    Février 2003
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2003
    Messages : 119
    Points : 136
    Points
    136
    Par défaut
    Hello,

    Non, rien a voir avec SendMail.
    Tu a télécharger JAF ?
    Regarde la fin de mon post précédent ??

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut
    oui je l'ai et j'ai aussi recupere le javamail
    j'ai ajoute ca a mon manifest

    CLass-Path : mail.jar activation.jar

    et j'ai copier les fichiers

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut
    bon ca y est mais j'ai une erreur sur le nom de domaine ????????
    "domaine name required for sender for sender adress toto"

  7. #7
    Membre habitué

    Profil pro
    Inscrit en
    Février 2003
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2003
    Messages : 119
    Points : 136
    Points
    136
    Par défaut
    Hello,

    La c'est surement une erreur dans les adresses ? Nan ?
    Il faut que les adresses du destinataire et de l'expéditeur existe, bien sur.

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut
    les 2 adresses existent

    quand j'execute ce programme, j'ai donc l'erreur
    mais quand j'envoi un message (via un logiciel ) directement du poste linux ca marche

  9. #9
    Membre habitué

    Profil pro
    Inscrit en
    Février 2003
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2003
    Messages : 119
    Points : 136
    Points
    136
    Par défaut
    Hello,

    La alors je vois pas. Est-ce que ton SMTP demande une authentification ?

  10. #10
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut
    oui pour celui je teste en ligne
    non pour le server linux que j'ai installé

  11. #11
    Membre habitué

    Profil pro
    Inscrit en
    Février 2003
    Messages
    119
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2003
    Messages : 119
    Points : 136
    Points
    136
    Par défaut
    Hello,

    Alors je viens de trouver ca , pour l'authentification

    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
     
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    import java.io.*;
     
    /*
      To use this program, change values for the following three constants,
     
        SMTP_HOST_NAME -- Has your SMTP Host Name
        SMTP_AUTH_USER -- Has your SMTP Authentication UserName
        SMTP_AUTH_PWD  -- Has your SMTP Authentication Password
     
      Next change values for fields
     
      emailMsgTxt  -- Message Text for the Email
      emailSubjectTxt  -- Subject for email
      emailFromAddress -- Email Address whose name will appears as "from" address
     
      Next change value for "emailList".
      This String array has List of all Email Addresses to Email Email needs to be sent to.
     
     
      Next to run the program, execute it as follows,
     
      SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();
     
    */
     
    public class SendMailUsingAuthentication
    {
     
      private static final String SMTP_HOST_NAME = "myserver.smtphost.com";
      private static final String SMTP_AUTH_USER = "myusername";
      private static final String SMTP_AUTH_PWD  = "mypwd";
     
      private static final String emailMsgTxt      = "Online Order Confirmation Message. Also include the Tracking Number.";
      private static final String emailSubjectTxt  = "Order Confirmation Subject";
      private static final String emailFromAddress = "sudhir@javacommerce.com";
     
      // Add List of Email address to who email needs to be sent to
      private static final String[] emailList = {"mark@yahoo.com", "robin@javacommerce.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);
        }
    }
     
    }
    Je l'ai pas testé 8)

  12. #12
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2003
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2003
    Messages : 124
    Points : 76
    Points
    76
    Par défaut
    ca marche nickel merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. erreur d'execution 3704, ...:objet n'est pas ouvert
    Par cari dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 29/11/2005, 15h44
  2. [ERREUR D'EXECUTION] Segmentation Fault
    Par CestPasMoi dans le forum C++
    Réponses: 3
    Dernier message: 26/11/2005, 17h38
  3. Réponses: 3
    Dernier message: 03/11/2005, 18h41
  4. [JavaMail]Erreur avec JavaMail
    Par Ethylene dans le forum API standards et tierces
    Réponses: 9
    Dernier message: 23/08/2005, 14h22
  5. [LDAP][Interface Winldap.h] Erreur d'execution
    Par -=Spoon=- dans le forum Autres SGBD
    Réponses: 2
    Dernier message: 10/03/2005, 17h10

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