简体   繁体   English

尝试在System.dll中使用smtp'System.Net.Mail.SmtpException'发送电子邮件时出错

[英]error when trying to send email using smtp 'System.Net.Mail.SmtpException' in System.dll

trying to send a password recovery email using the smpt protocol in c# and for some reason I can't seem to get it right. 尝试使用c#中的smpt协议发送密码恢复电子邮件,由于某种原因,我似乎无法正确处理它。 I will highly appreciate it of someone could help. 我非常感谢有人可以提供帮助。 This is what I was relying on . 这就是我所依赖 And Here's the code: 这是代码:

enter cpublic void sendEmailWithPass( string username , string email , string password)
    {
        try
        {
            var fromAddress = new MailAddress("xxx", "xxx");
            var toAddress = new MailAddress(email, "CLIENT!");
            const string fromPassword = "xxx";
            string subject = "recover password";
            string body = "heloo! \n according to your request your password is: \n " + password;
            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); }
            SendMessage("&answerForgotRequest&true!");
        }
        catch
        {
            SendMessage("&answerForgotRequest&failed!");
        }            
    }

in addition, this is the line which corresponds to the error 另外,这是与错误相对应的行

 public void answerServer(string message)
    {
        string ans = message.Split('&')[2];

 if (ans.StartsWith("failed!"))
        {
            MessageBox.Show("an error was occured while trying sending the mail");
        }

] ]

Since you are struggling with this, you need to at least try to catch the exception , no-one can help you as you are just throwing it away 由于您正在为此而苦苦挣扎,因此至少需要尝试捕获exception ,因为您只是将其丢弃,所以没有人可以为您提供帮助

try
{
    // email code
}
catch(Exception ex)
{
    // breakpoint this line (yes look up online how to do it)
    MessageBox.Show(Ex.ToString());
    // write it to file if you need to
    //File.WriteAllText("someFileName.Txt",Ex.ToString() );
} 

Then when you have an actual exception, please paste (or ask a new question) it so we know whats happening. 然后,当您遇到实际异常时,请粘贴(或提出新问题),以便我们知道发生了什么。

You might want to have a look at these too 您可能也想看看这些

Exception Handling (C# Programming Guide) 异常处理(C#编程指南)

Navigate through code with the Visual Studio debugger 使用Visual Studio调试器浏览代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MailMessage System.Net.Mail.SmtpException,尝试通过 C# 表单发送 email 时出错 - MailMessage System.Net.Mail.SmtpException, Error when trying to send email via C# form System.dll中发生了类型为'System.Net.Mail.SmtpException'的未处理的异常 - An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll System.dll中发生类型'System.Net.Mail.SmtpException'的异常,但未在用户代码中处理 - An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code 出现错误:-System.net.mail.SmtpException - Getting error:-System.net.mail.SmtpException System.Net.Mail.SmtpException: 操作已超时。 asp.net 中的错误使用godaddy 托管发送邮件代码 - System.Net.Mail.SmtpException: The operation has timed out. error in asp.net send mail code using godaddy hosting System.Net.Mail.SmtpException {“发送电子邮件失败。”} - System.Net.Mail.SmtpException {“Failure Sending Email.”} System.Net.Mail.SmtpException:邮箱不可用 - System.Net.Mail.SmtpException: Mailbox unavailable 将白名单IP gmail smtp-System.Net.Mail.SmtpException:发送邮件失败 - Whitelist IP gmail smtp - System.Net.Mail.SmtpException: Failure sending mail System.dll 中发生 SmtpException - SmtpException occurring in System.dll System.Net.Mail.SmtpException:SMTP 服务器需要安全连接或客户端未通过身份验证 - System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM