envoie mail avec C++ Builder (Erreur de socket n° 11001 Hôte non trouvé.)
Bonsoir, j'ai un problème avec C++ Builder. Je souhaite envoyer des mail via une application or cela ne fonctionne pas.
Composants de l'App:
Voici mon code pour le moment :
Code:
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
|
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Click(TObject *Sender)
{
this->Edit1->SelectAll(); //Ergonomie
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2Click(TObject *Sender)
{
this->Edit2->SelectAll(); //Ergonomie
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
this->IdMessage1->From->Text = "monmail@gmail.com"; //Fonctionne
this->IdMessage1->ReplyTo->EMailAddresses = "monmail@gmail.com"; //Fonctionne
this->IdMessage1->Recipients->EMailAddresses = "monmail@gmail.com"; //Fonctionne
this->IdMessage1->Subject = "Nouvelle demande de contact"; //Fonctionne
this->IdMessage1->Body->Add("Adresse mail: " +
this->Edit1->Text + "/n" +
"Sujet de la demande: " +
this->Edit2->Text); //Fonctionne
this->IdSMTP1->Username = "monmail@gmail.com"; //Fonctionne
this->IdSMTP1->Password = "MotDePasseDeMonMail"; //Fonctionne
this->IdSMTP1->Host = "smtp.gmail.com"; //"Fonctionne" (J'ai tester de changer les différents serveurs proposés par google)
this->IdSMTP1->Port = 25; //"//Fonctionne"
try
{
this->IdSMTP1->Connect(5000); //Erreur ici
this->IdSMTP1->Send(this->IdMessage1);
this->IdSMTP1->Disconnect();
}
catch(Exception &e)
{
ShowMessage (e.Message);
}
}
//--------------------------------------------------------------------------- |
J'ai tester différentes méthode tel que changer de messagerie (orange, outlook) ensuite j'ai également un nom de domaine avec un hébergement mail alors j'ai tenter de l'utiliser (l'option sans SSL) et l'erreur reviens toujours.
Erreur C++ Builder :
Code:
1 2 3 4 5
|
Exception 'first chance' à $75A3C54F. Classe d'exception EIdSocketError avec un message
'Erreur de socket n° 11001
Hôte non trouvé.'.
Processus Project1.exe (4368) |
Erreur dans l'App :
Code:
1 2 3
|
Erreur de socket n° 11001
Hôte non trouvé. |
Edit: 30.03.2018 11:13 J'ai essayé avec un nouveau code toujours la même erreur.
Code:
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
|
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
#pragma resource ("*.Windows.fmx", _PLAT_MSWINDOWS)
#pragma resource ("*.Surface.fmx", _PLAT_MSWINDOWS)
TForm1 *Form1;
void TForm1::Gmail(UnicodeString username,
UnicodeString password,
UnicodeString totarget,
UnicodeString subject,
UnicodeString body)
{
TIdSSLIOHandlerSocketOpenSSL *SSL;
SSL = this->IdSSLIOHandlerSocketOpenSSL1; // Renommer un composant
TIdMessage *DATA;
DATA = this->IdMessage1; //Renommer un composant
TIdSMTP *SMTP;
SMTP = this->IdSMTP1; //Renommer un composant
SSL->SSLOptions->Method = sslvTLSv1;
SSL->SSLOptions->Mode = sslmUnassigned;
SSL->SSLOptions->VerifyMode = (TIdSSLVerifyModeSet) 0;
DATA->From->Address = username;
DATA->Recipients->EMailAddresses = username;
DATA->Subject = subject;
DATA->Body->Text = body;
SMTP->IOHandler = SSL;
SMTP->Host = "smtp.gmail.com";
SMTP->Port = 465;
SMTP->Username = username;
SMTP->Password = password;
SMTP->UseTLS = utUseExplicitTLS;
SMTP->Connect(5000);
SMTP->Send(DATA);
SMTP->Disconnect();
SMTP->Free();
DATA->Free();
SSL->Free();
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// this->IdMessage1->From->Text = "monmail@gmail.com";
// this->IdMessage1->ReplyTo->EMailAddresses = "monmail@gmail.com";
// this->IdMessage1->Recipients->EMailAddresses = "monmail@gmail.com";
// this->IdMessage1->Subject = this->Edit2->Text;
// this->IdMessage1->Body->Add("Nom: " +
// this->Edit1->Text + "/n" +
// "Mail: " +
// this->Edit3->Text + "/n" +
// "Message: " +
// this->Edit4->Text);
//
// this->IdSMTP1->AuthType=1;
// this->IdSMTP1->Username = "monmail@gmail.com";
// this->IdSMTP1->Password = "monpass"; //Mot de passe à mettre
// this->IdSMTP1->Host = "smtp.gmail.com";
// this->IdSMTP1->Port = 465;
// try
// {
// this->IdSMTP1->Connect(5000);
// this->IdSMTP1->Send(this->IdMessage1);
// this->IdSMTP1->Disconnect();
// }
// catch(Exception &e)
// {
// ShowMessage(e.Message);
// }
mail_username = "monmail@gmail.com";
mail_password = "monpass";
mail_to = "monmail@gmail.com";
mail_subject = this->Edit2->Text;
mail_body = this->Edit4->Text;
try
{
Gmail(mail_username, mail_password, mail_to, mail_subject, mail_body);
}
catch(Exception &e)
{
ShowMessage(e.Message);
}
}
//--------------------------------------------------------------------------- |
Merci de votre aide j'espère que vous aurez une idée d'où le problème pourrait venir.
Cordialement,
Lucas.