Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

envoyer un e-mail avec C#

3 réponses
Avatar
Maurice
Bonjour:

j'essaye d'écrire un petit programme permettant d'envoyer un e-mail avec C#,
j'ai fait une petite recherche, j'ai trouvé un morceau de code, que j'ai
légèrement modifié comme suit:


using System;
using System.Windows.Forms;
using System.Net.Mail;

public class sendmail
{
public static void Main(string[] args){
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.mail.yahoo.fr");

try{
mail.From = new MailAddress("xyz@yahoo.fr");
mail.To.Add("xyz@yahoo.fr");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail";

SmtpServer.Port = 465;
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz",
"4589");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
System.Console.Error.WriteLine(ex.ToString());
}
}
}

J'ai compilé avec la commande:
"d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc"
e:\my_data\prog\c#\sendmail.cs

resultat OK, sendmail.exe généré.

Mais quand je lance "sendmail", j'obtiens les erreurs suivantes:

System.Net.Mail.SmtpException: Failure sending mail. --->
System.IO.IOException:
Unable to read data from the transport connection: An existing connection
was f
orcibly closed by the remote host. ---> System.Net.Sockets.SocketException:
An e
xisting connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32
size,
SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 s
ize)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 s
ize)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32
count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32
coun
t)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader
caller, B
oolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader
caller)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at sendmail.Main(String[] args)

Quelqu'un aura une idée où est-ce l'erreur?

Merci d'avance

Maurice

3 réponses

Avatar
alain
"Maurice" a écrit dans le message de news:
h38484$crc$

System.Net.Mail.SmtpException: Failure sending mail. --->
System.IO.IOException:
Unable to read data from the transport connection: An existing connection
was f
orcibly closed by the remote host. --->
System.Net.Sockets.SocketException:



Tu as vérifié si ça ne vient pas du Firewall, en le désactivant ?
Sinon, tu peux télécharger Wireshark pour avoir une analyse des paquets
transmis sur le réseau
Avatar
alain
"Maurice" a écrit dans le message de news:
h39nc8$v85$

Merci pour votre réponse,
En fait, j'ai jamais travaillé avec les firewalls, mais pour essayer, je
suis aller dans Control Panel --> windows firewall --> exeptions --> Add
Program, puis j'ai ajouté sendmail.exe à la liste, puis OK etc...
Mais ça n'a rien changé, j'ai eu à nouveau le même message d'erreur



Je parlais de le désactiver temporairement pour tester (ça peut être une des
causes, d'après d'anciens posts)
Mais voir plutot avec Wireshark pour essayer d'avoir une cause d'erreur plus
précise.
Avatar
Maurice
"alain" wrote in message news:h3890r$i3r$
"Maurice" a écrit dans le message de news:
h38484$crc$

System.Net.Mail.SmtpException: Failure sending mail. --->
System.IO.IOException:
Unable to read data from the transport connection: An existing connection
was f
orcibly closed by the remote host. --->
System.Net.Sockets.SocketException:



Tu as vérifié si ça ne vient pas du Firewall, en le désactivant ?
Sinon, tu peux télécharger Wireshark pour avoir une analyse des paquets
transmis sur le réseau




Merci pour votre réponse,
En fait, j'ai jamais travaillé avec les firewalls, mais pour essayer, je
suis aller dans Control Panel --> windows firewall --> exeptions --> Add
Program, puis j'ai ajouté sendmail.exe à la liste, puis OK etc...
Mais ça n'a rien changé, j'ai eu à nouveau le même message d'erreur


Maurice