System.dll中出现“System.Net.Mail.SmtpException”类型的异常,但未在用户代码中处理

时间:2017-08-31 11:29:34

标签: c# asp.net asp.net-mvc smtp

我设置了所有参数,但是我得到了异常:System.dll中出现“System.Net.Mail.SmtpException”类型的异常,但未在用户代码中处理

请帮助解决这个问题。

        var verifyUrl = "/User/VerifyAccount" + activateCode;
        var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);

        var fromEmail = new MailAddress("******@gmail.com", "Dotnet Awesome");
        var toEmail = new MailAddress(email);
        var fromEmailPassword = "******";
        string subject = "Your account is successfully created!";

        string body = "<br/><br/>We are excitef to tell you Dotnet Awesome is" +
            "successfully created. Please click on the link to verify your account" +
            "<a href'" + link + "'>" + link + "</a>";

        var smtp = new SmtpClient
        {
            Host = "smpt.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword)
        };

        using (var message = new MailMessage(fromEmail, toEmail)
        {
            Subject = subject,
            Body = body,
            IsBodyHtml = true
        })
        {
            smtp.Send(message);//Exception here
        }

1 个答案:

答案 0 :(得分:-1)

我认为您可以检查此主机=“ smpt.gmail.com”,因为您使用了smpt而不是smtp