C#发送邮件失败 [英] C# sending mails failed
本文介绍了C#发送邮件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我试图弄清楚我的项目突然发生了什么.它工作正常,但现在不行了.
这是堆栈跟踪
Hi All,
I am trying to figure out what suddenly happened to my project. It was working fine but now its not.
this is stack trace
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at WindowsKeyloggerTool.frmSettings.SendTestMail(String message) in c:\users\avinash\documents\visual studio 2010\Projects\WindowsKeyloggerTool\WindowsKeyloggerTool\frmSettings.cs:line 103
at WindowsKeyloggerTool.frmSettings.ValidateUserCredentials() in c:\users\avinash\documents\visual studio 2010\Projects\WindowsKeyloggerTool\WindowsKeyloggerTool\frmSettings.cs:line 75
and inner exception
Unable to find an entry point named ''EnumerateSecurityPackagesW'' in DLL ''security.dll''.
at System.Net.UnsafeNclNativeMethods.SafeNetHandles_SECURITY.EnumerateSecurityPackagesW(Int32& pkgnum, SafeFreeContextBuffer_SECURITY& handle)
at System.Net.SafeFreeContextBuffer.EnumeratePackages(SecurDll Dll, Int32& pkgnum, SafeFreeContextBuffer& pkgArray)
at System.Net.SSPISecureChannelType.EnumerateSecurityPackages(Int32& pkgnum, SafeFreeContextBuffer& pkgArray)
at System.Net.SSPIWrapper.EnumerateSecurityPackages(SSPIInterface SecModule)
at
请帮助我.
Please help me.
推荐答案
您如何尝试这个.....
首先检查连接...
How about you try this.....
first check connection...
public bool Checking_Internet_Connection()
{
try
{
System.Net.Sockets.TcpClient clnt = new System.Net.Sockets.TcpClient("www.google.com", 80);
clnt.Close();
return true;
}
然后将邮件发送到所需的电子邮件地址....
then send message to required email address....
public void Send_Email(Email_Message_Details Email_msg_details)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("gmailaccount");
mail.To.Add("email address you want to send");
mail.Subject = Email_msg_details.SUBJECT;
mail.Body = Email_msg_details.BODYMESSAGE;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("gmailaccount", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
catch
{
return;
}
}
这篇关于C#发送邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文