6

我在通过 C# 发送邮件时遇到异常

SmtpClient client = new SmtpClient() 

作为System.Security.Cryptography.CryptographicException:句柄无效。

MailMessage mail = new MailMessage(from,to);

            mail.To.Add(to);
            mail.From = new MailAddress(from, "", System.Text.Encoding.UTF8);

            mail.Subject = "This is a test mail";

            mail.SubjectEncoding = System.Text.Encoding.UTF8;

            mail.Body = fr.message;

            mail.BodyEncoding = System.Text.Encoding.UTF8;

            mail.IsBodyHtml = true;

            mail.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient();

            //Add the Creddentials- use your own email id and password
            client.Credentials = new System.Net.NetworkCredential(from, Password);

            client.Port = 587; // Gmail works on this port

            client.Host = "smtp.gmail.com";

            client.EnableSsl = true; //Gmail works on Server Secured Layer

                client.Send(mail);

我不明白为什么会这样?

4

1 回答 1

1

检查您的项目设置并确保您已检查 NTLM 身份验证:

在此处输入图像描述

于 2013-11-05T02:00:58.860 回答