Bonjour, j'ai un problème lors de l'authentification sur le serveur smtp de Google Mail afin d'envoyer un mail via une application WinForm en c#
Voilà le code que j'utilise :
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
 
using System.Net.Mail;
using System.Net;
 
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
 
                mail.From = new MailAddress("username@gmail.com");
                mail.To.Add("mailto@live.fr");
                mail.Subject = "Test Mail";
                mail.Body = "Test d'envoi de mail";
 
                SmtpServer.Port = 587; // ou avec le port 465 j'ai aussi essayé
                SmtpServer.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");
                SmtpServer.EnableSsl = true;
 
                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
et voici l'exception levé :
System.Net.Mail.SmtpException: Échec d'envoi du courrier. ---> System.Net.WebException: Impossible de se connecter au serveur distant ---> System.Net.Sockets.SocketException: Une tentative d’accès à un socket de manière interdite par ses autorisations d’accès a été tentée 209.85.227.109:25
à System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
à System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- Fin de la trace de la pile d'exception interne ---
à System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
à System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
à System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
à System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
à System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
à System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
à System.Net.Mail.SmtpClient.GetConnection()
à System.Net.Mail.SmtpClient.Send(MailMessage message)
--- Fin de la trace de la pile d'exception interne ---
à System.Net.Mail.SmtpClient.Send(MailMessage message)
à CameraAforge.Form1.btnMail_Click(Object sender, EventArgs e) dans C:\Users\OnganMe\Desktop\CameraAforge\CameraAforge\Form1.cs:ligne 150

à la ligne 150 se trouve le SmtpServer.Send(mail);
Quelqu'un pourrait m'aider à résoudre cela ?