3

这是相关代码(C#)

                    MailMessage m;
                    SmtpClient client;   

                    client.Host = "smtp.mail.yahoo.com";
                    client.Port = 465;  
                    client.EnableSsl = true;
                    client.Credentials = new NetworkCredential("mymail@yahoo.com", "mypassword");

                    m = new MailMessage();
                    m.From = new MailAddress("mymail@yahoo.com");
                    m.To.Add(new MailAddress("anothermail@gmail.com"));
                    m.Subject = "My subject";
                    m.Body = "This is my body. ";

                    client.Send(m);

这是完整的错误跟踪

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing 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 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
   at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
   at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
   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 EmailSender.EmailSenderForm.send() in c:\Users\Ankur\Documents\Visual Studio 2012\Projects\EmailSender\EmailSender\EmailSenderForm.cs:line 91

我在这里做错了什么?

4

1 回答 1

2

据我所知,雅虎不允许第三方邮件客户端操作他们的账户。这就是为什么你需要使用 Thunderbird 的 webmail 扩展。雅虎为这些服务提供他们的雅虎邮箱加号。您可以在 Gmail 中使用另一个邮件帐户尝试您的应用程序吗?在那里它应该可以正常工作。

我为 Outlook 帐户配置了此代码以发送电子邮件。我现在已经工作了两年,没有任何修改。它应该开箱即用(只需更改帐户名称):

MailMessage mm = new MailMessage(@"example@hotmail.com",
                     dest, textBox1.Text, richTextBox1.Text);
SmtpClient client = new SmtpClient("smtp.live.com", 587);
client.Credentials = new NetworkCredential(@"examplehotmail.com", "password");
client.EnableSsl = true;
messageSent = false;
client.SendAsync(mm, null);
client.SendCompleted += SentMessageTrigger;

我希望它有所帮助。

于 2013-04-29T20:58:26.447 回答