using System.Net;
using System.Net.Mail;
var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@example.com", "To Name");
string fromPassword = "fromPassword";
string subject = "Subject";
string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
System.Net.Mail.SmtpException
HResult=0x80131500
Message=Failure sending mail.
Source=System
StackTrace:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Microsoft.Dynamics365.UIAutomation.Sample.UCI.CasePage.SendEmail(Byte[] stream, String pageName, DateTime screenshotTime) in This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
IOException: Unable to read data from the transport connection: net_io_connectionclosed.
Pls help me with this error.
3条答案
按热度按时间dsekswqp1#
这不仅仅是一个Selenium问题,更多的是基于C#。
有一个完整的网站专门详细解释了如何使用C#和System.Net.Mail命名空间发送电子邮件:
http://www.systemnetmail.com/
举个简单的例子:
您所需要做的就是通过读入您提到的"reports"的内容来构造消息正文。
1tu0hz3e2#
谢谢你的代码。
我发现一些代码发送电子邮件附件。
有关详细信息,请阅读Sending email using SmtpClient。
谢谢你。
rxztt3cl3#