【问题标题】:Sending email from c# code [duplicate]从c#代码发送电子邮件[重复]
【发布时间】:2013-06-22 18:53:11
【问题描述】:

我正在尝试从我的 C# 代码发送电子邮件。这是一个示例

MailMessage message = new MailMessage();
            message.To.Add("milos90zr@gmail.com");
            message.Subject = "Registration";
            message.From = new System.Net.Mail.MailAddress("milos90zr@hotmail.com");
            message.Body = "OK";
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Send(message);

但是我的代码中断了,这是错误:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. hn4sm3874638bkc.2 - gsmtp

【问题讨论】:

  • 您需要使用NetworkCredential 对象进行身份验证。

标签: c# email


【解决方案1】:

您必须打开加密。

将此行放在smtp.Send()之前的某处

smtpClient.EnableSsl = true;

【讨论】:

    猜你喜欢
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多