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

Réseau C Discussion :

Socket connexion smtp =>erreur 10026


Sujet :

Réseau C

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 16
    Points
    16
    Par défaut Socket connexion smtp =>erreur 10026
    Bonjour,
    J'ai un gros souci, en fait ça fait plus de deux jours que je m'acharne sur mon code, au niveau de la syntaxe je ne pense pas qu'il y est de gros probleme puisque j'arrive à compiler, oui je sais...ça ne veut strictement rien dire...

    Voici mon probleme, j'essai d'envoi par mail un fichier log qui se trouve sur mon poste via socket sur serveur SMTP. Mais j'ai l'impression que la liaison ne se fait pas.
    Je precise que je me connecte sur internet via un hotspot (peut etre quelque chose qui bloque la connexion)

    Resultat sur mon DOS j'ai un retour '10060' (Afficher en Rouge dans le code)

    merci pour votre aide.
    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
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    #include <stdio.h>
    #include <stdlib.h>
    #include <tchar.h>
    #include <windowsx.h>
    #include <stdlib.h>
    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h> 
    
        
        #define BUFSIZE 800
        #define waittime 500
    
     #define cmailserver "alt1.gmail-smtp-in.l.google.com"
     #define cemailto "delichok@gmail.com"
     #define cemailfrom "destinataire@gmail.com"
     #define LogLength 100
     #define FileName "sound.wav"
     #define cemailsubject "Subject test"
     #define cemailmessage "test contenu du message"
     
     #define SMTPLog "c:\\Smtplog.log"
     
    char    FILENAME[] = "c:\\log.log";     // Chemin du log
    
    int MailIt (char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char *emailmessage);
    
    int main(int argc, char *argv[])
    {
      MailIt (cmailserver, cemailto, cemailfrom, cemailsubject, cemailmessage);
      
      system("PAUSE");	
      return 0;
    }
    
    int SendMail (char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char *emailmessage) {
         SOCKET sockfd;
         WSADATA wsaData;
         FILE *smtpfile;
        
         #define bufsize 300 // taille du fichier pour l' envoie
         int bytes_sent;
         int err;
         struct hostent *host; /* gethostbyname */
         struct sockaddr_in dest_addr; /* adresse de l'hote */
         char line[1000];
         char *Rec_Buf = (char*) malloc(bufsize+1);
         
         smtpfile=fopen(SMTPLog,"a+");
         
         if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR) {
             fputs("WSAStartup failed",smtpfile);
             WSACleanup();
             return -1;
         }
         if ( (host=gethostbyname(mailserver)) == NULL) {
             perror("gethostbyname");
             exit(1);
         }
         memset(&dest_addr,0,sizeof(dest_addr));
         memcpy(&(dest_addr.sin_addr),host->h_addr,host->h_length);
        
         /* Prepare dest_addr */
         dest_addr.sin_family= host->h_addrtype;
         dest_addr.sin_port= htons(25); /* PORT */
        
         if ((sockfd=socket(AF_INET,SOCK_STREAM,0)) < 0) {
             perror("socket");
             exit(1);
         }
         /* Connection !*/
         fputs("Connecting....\n",smtpfile);
        
         if (connect(sockfd, (struct sockaddr *)&dest_addr,sizeof(dest_addr)) == -1){
             
             printf("Erreur lors de la connexion %d", WSAGetLastError());
    
    // Apres debugage le code s'arrete ici avec un retour '10060'
    
             perror("connect");
             exit(1);
         }
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         strcpy(line,"helo me.somepalace.com\n");
         fputs(line,smtpfile);
         bytes_sent=send(sockfd,line,strlen(line),0);
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         strcpy(line,"MAIL FROM:<");
         strncat(line,emailfrom,strlen(emailfrom));
         strncat(line,">\n",3);
         fputs(line,smtpfile);
         bytes_sent=send(sockfd,line,strlen(line),0);
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         strcpy(line,"RCPT TO:<");
         strncat(line,emailto,strlen(emailto));
         strncat(line,">\n",3);
         fputs(line,smtpfile);
         bytes_sent=send(sockfd,line,strlen(line),0);
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         strcpy(line,"DATA\n");
         fputs(line,smtpfile);
         bytes_sent=send(sockfd,line,strlen(line),0);
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         Sleep(waittime);
         strcpy(line,"To:");
         strcat(line,emailto);
         strcat(line,"\n");
         strcat(line,"From:");
         strcat(line,emailfrom);
         strcat(line,"\n");
         strcat(line,"Subject:");
         strcat(line,emailsubject);
         strcat(line,"\n");
         strcat(line,emailmessage);
         strcat(line,"\r\n.\r\n");
         fputs(line,smtpfile);
         bytes_sent=send(sockfd,line,strlen(line),0);
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         strcpy(line,"quit\n");
         fputs(line,smtpfile);
         bytes_sent=send(sockfd,line,strlen(line),0);
         Sleep(waittime);
         err=recv(sockfd,Rec_Buf,bufsize,0);Rec_Buf[err] = '\0';
         fputs(Rec_Buf,smtpfile);
         fclose(smtpfile);
         #ifdef WIN32
         closesocket(sockfd);
         WSACleanup();
         #else
         close(sockfd);
         #endif
         return 0;
     } 
    //==============================================================================
    // EOF
    //==============================================================================

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 581
    Points
    41 581
    Par défaut
    10060 signifie "timeout", donc il est très probable en effet qu'il y ait un pare-feu ou un truc du genre, qui bloque la connexion.

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 16
    Points
    16
    Par défaut
    Merci pour ta réactivité.

    Existe-t-il un moyen de contourner ce problème ?

    Merci par avance.

  4. #4
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par dabaton Voir le message
    J'ai un gros souci, en fait ça fait plus de deux jours que je m'acharne sur mon code, au niveau de la syntaxe je ne pense pas qu'il y est de gros probleme puisque j'arrive à compiler,
    Pas moi. ton code est incomplet...
    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
     
    -------------- Build: Debug in hello ---------------
     
    Compiling: main.c
    Linking console executable: bin\Debug\hello.exe
    C:\dev\hello\main.c: In function `main':
    C:\dev\hello\main.c:31: warning: passing arg 1 of `MailIt' discards qualifiers from pointer target type
    C:\dev\hello\main.c:31: warning: passing arg 2 of `MailIt' discards qualifiers from pointer target type
    C:\dev\hello\main.c:31: warning: passing arg 3 of `MailIt' discards qualifiers from pointer target type
    C:\dev\hello\main.c:31: warning: passing arg 4 of `MailIt' discards qualifiers from pointer target type
    C:\dev\hello\main.c:31: warning: passing arg 5 of `MailIt' discards qualifiers from pointer target type
    C:\dev\hello\main.c: At top level:
    C:\dev\hello\main.c:29: warning: unused parameter 'argc'
    C:\dev\hello\main.c:29: warning: unused parameter 'argv'
    C:\dev\hello\main.c: In function `SendMail':
    C:\dev\hello\main.c:72: warning: comparison of unsigned expression < 0 is always false
    C:\dev\hello\main.c:74: warning: will never be executed
    obj\Debug\main.o: In function `main':
    C:/dev/hello/main.c:31: undefined reference to `_MailIt'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 1 seconds)
    1 errors, 9 warnings
    Citation Envoyé par dabaton Voir le message
    Voici mon probleme, j'essai d'envoi par mail un fichier log qui se trouve sur mon poste via socket sur serveur SMTP. Mais j'ai l'impression que la liaison ne se fait pas.
    Je precise que je me connecte sur internet via un hotspot (peut etre quelque chose qui bloque la connexion)

    Resultat sur mon DOS j'ai un retour '10060' (Afficher en Rouge dans le code)
    Chez moi, ceci
    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
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
     
    #include <winsock2.h>
    #include <stdio.h>
     
    #define SMTPLog "Smtplog.log"
     
    struct email
    {
       char const *server;
       char const *from;
       char const *to;
       char const *subject;
       char const *message;
    };
     
    static int receive (SOCKET sockfd, FILE * smtpfile)
    {
       int err = 0;
       char Rec_Buf[1024];
       int n = recv (sockfd, Rec_Buf, sizeof Rec_Buf - 1, 0);
       if (n >= 0)
       {
          Rec_Buf[n] = '\0';
          fputs (Rec_Buf, smtpfile);
       }
       else
       {
          err = 1;
       }
       return err;
    }
     
    static int send_txt (SOCKET sockfd, FILE * smtpfile, char const *line)
    {
       int err;
       int n = send (sockfd, line, strlen (line), 0);
       fputs (line, smtpfile);
       err = n < 1;
       return err;
    }
     
    static int dialogue (SOCKET sockfd, FILE * smtpfile, struct email *p_email)
    {
       int err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
       err = send_txt (sockfd, smtpfile, "helo me.somepalace.com\n");
       if (err)
          goto end;
     
       err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
       {
          char line[256];
          strcpy (line, "MAIL FROM:<");
          strcat (line, p_email->from);
          strcat (line, ">\n");
          err = send_txt (sockfd, smtpfile, line);
       }
       if (err)
          goto end;
     
       err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
       {
          char line[256];
          strcpy (line, "RCPT TO:<");
          strcat (line, p_email->to);
          strcat (line, ">\n");
          err = send_txt (sockfd, smtpfile, line);
       }
       if (err)
          goto end;
     
       err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
       err = send_txt (sockfd, smtpfile, "DATA\n");
       if (err)
          goto end;
     
       err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
       {
          char line[512];
          strcpy (line, "To:");
          strcat (line, p_email->to);
          strcat (line, "\n");
          strcat (line, "From:");
          strcat (line, p_email->from);
          strcat (line, "\n");
          strcat (line, "Subject:");
          strcat (line, p_email->subject);
          strcat (line, "\n");
          strcat (line, p_email->message);
          strcat (line, "\r\n.\r\n");
          err = send_txt (sockfd, smtpfile, line);
       }
       if (err)
          goto end;
     
       err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
       err = send_txt (sockfd, smtpfile, "quit\n");
       if (err)
          goto end;
     
       err = receive (sockfd, smtpfile);
       if (err)
          goto end;
     
     end:
       return err;
    }
     
    static int SendMail (struct email *p_email)
    {
    #define waittime 500
    #define bufsize 300             /* taille du fichier pour l' envoie */
       FILE *smtpfile = fopen (SMTPLog, "w");
       if (smtpfile != NULL)
       {
          WSADATA wsaData;
          if (WSAStartup (0x202, &wsaData) != SOCKET_ERROR)
          {
             struct hostent *host = gethostbyname (p_email->server);
     
             if (host != NULL)
             {
     
                SOCKET sockfd = socket (AF_INET, SOCK_STREAM, 0);
     
                if (sockfd != INVALID_SOCKET)
                {                   /* Connection ! */
                   struct sockaddr_in dest_addr; /* adresse de l'hote */
                   memset (&dest_addr, 0, sizeof (dest_addr));
                   memcpy (&(dest_addr.sin_addr), host->h_addr, host->h_length);
                   /* Prepare dest_addr */
                   dest_addr.sin_family = host->h_addrtype;
                   dest_addr.sin_port = htons (25); /* PORT */
     
                   fputs ("Connecting....\n", smtpfile);
     
                   if (connect
                       (sockfd, (struct sockaddr *) &dest_addr,
                        sizeof (dest_addr)) != SOCKET_ERROR)
                   {
                      dialogue (sockfd, smtpfile, p_email);
                   }
                   else
                   {
                      fprintf (smtpfile, "Erreur lors de la connexion %d\n",
                               WSAGetLastError ());
     
    /* Apres debugage le code s'arrete ici avec un retour '10060' */
     
                      fputs ("connect failed\n", smtpfile);
                   }
                }
                else
                {
                   fputs ("socket failed\n", smtpfile);
                }
             }
             else
             {
                fputs ("gethostbyname failed\n", smtpfile);
             }
     
             WSACleanup ();
          }
          else
          {
             fputs ("WSAStartup failed\n", smtpfile);
          }
          fclose (smtpfile);
       }
       return 0;
    }
     
    int main (void)
    {
    #define cmailserver "alt1.gmail-smtp-in.l.google.com"
    #define cemailto "delichok@gmail.com"
    #define cemailfrom "origine@gmail.com"
    #define cemailsubject "Subject test"
    #define cemailmessage "test contenu du message"
       struct email email = {
          cmailserver, cemailfrom, cemailto, cemailsubject, cemailmessage
       };
       SendMail (&email);
     
       return 0;
    }
    donne ce log :
    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
     
    Connecting....
    220 mx.google.com ESMTP g22si26487118rvb.1
     
    helo me.somepalace.com
    250 mx.google.com at your service
     
    MAIL FROM:<origine@gmail.com>
    250 2.1.0 OK g22si26487118rvb.1
     
    RCPT TO:<delichok@gmail.com>
    550-5.1.1 The email account that you tried to reach does not exist. Please
     
    550-5.1.1 try double-checking the recipient's email address for typos
     
    550-5.1.1 or unnecessary spaces. Learn more at                     
     
    550 5.1.1 http://mail.google.com/support/bin/answer.py?answer=6596 g22si26487118rvb.1
     
    DATA
    503 5.5.1 RCPT first. g22si26487118rvb.1
     
    To:delichok@gmail.com
    From:origine@gmail.com
    Subject:Subject test
    test contenu du message
     
    .
     
    502 5.5.1 Unrecognized command. g22si26487118rvb.1
     
    quit
    502 5.5.1 Unrecognized command. g22si26487118rvb.1
    J'ai essayé avec mon adresse gmail et j'ai reçu :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    de	origine@gmail.com
    à	emmanuel dot delahaye at gmail.com
    date	31 décembre 2008 04:09
    objet	Subject test
     
    test contenu du message

  5. #5
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par dabaton Voir le message
    Existe-t-il un moyen de contourner ce problème ?
    Si tu n'as pas accès à certains services, tu dois voir l'administrateur du réseau...

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2008
    Messages : 21
    Points : 16
    Points
    16
    Par défaut
    Merci à toi Emmanuel pour ton test. Effectivement avec une connexion internet normal (sans passer par hostpot) alors je reçois bien le mail avec ma piece jointe, quoique... l'email arrive sans l'adresse de l'expiditeur que j'ai pris soin d'indiqué dans la ligne MIME avec "MAIL FROM:<origine@gmail.com>\r\n"",
    mais bon...on verra plus tard.
    En tout cas merci pour votre aide.

Discussions similaires

  1. Socket connexion permanente
    Par vodevil dans le forum Programmation et administration système
    Réponses: 7
    Dernier message: 12/07/2006, 22h10
  2. [Socket]Connexion au port distant 161
    Par arsenik7 dans le forum Entrée/Sortie
    Réponses: 8
    Dernier message: 22/11/2005, 17h14
  3. [MFC] Problème Socket + Connexion SQL
    Par BananaUltra3C dans le forum MFC
    Réponses: 6
    Dernier message: 20/05/2005, 16h41
  4. [socket] connexion à un serveur irc
    Par soad dans le forum Entrée/Sortie
    Réponses: 7
    Dernier message: 19/11/2004, 02h59
  5. [SOCKET] connexion client serveur avec applet
    Par kaiser2003 dans le forum Applets
    Réponses: 2
    Dernier message: 06/10/2004, 22h32

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