简体   繁体   English

使用 NTLM 在 C# 中发送电子邮件

[英]Send Email in C# using NTLM

I need to send email using NTLM, currently, I'm using the following code to send email我需要使用 NTLM 发送电子邮件,目前,我使用以下代码发送电子邮件

SmtpClient objSmtpClient;
        System.Net.NetworkCredential objNetworkCredential;
        objSmtpClient = new SmtpClient("10.xxx.xxx.xxx", 587);
        objSmtpClient.EnableSsl = true;
        objNetworkCredential = new System.Net.NetworkCredential(userName, password);
        try
        {
            string to = txtto.Text;
            MailMessage objMailMessage = new MailMessage();
            objMailMessage.From = new MailAddress("from@email.com", "sendername");
            objMailMessage.To.Add(new MailAddress("to@email.com"));
            objMailMessage.Subject = "subject";
            objMailMessage.Body = "body";
            objMailMessage.IsBodyHtml = true;
            objSmtpClient.EnableSsl = true;
            objSmtpClient.UseDefaultCredentials = true;
            objSmtpClient.Credentials = objNetworkCredential;
            objSmtpClient.Send(objMailMessage);
        }
        catch (Exception ex)
        {
         MessageBox.Show(ex.Message + " INNER EXCEPTION > "+ex.InnerException +" DATA > "+ex.Data);  
        }

The Above code works if I try to change the port to 25 and EnableSSL to false, But when I try to send it using 587 and setting EnableSSL to true it doesn't work.如果我尝试将端口更改为 25 并将 EnableSSL 更改为 false,则上述代码有效,但是当我尝试使用 587 发送它并将 EnableSSL 设置为 true 时,它​​不起作用。

I'm getting the following error, sometimes I get an Invalid Certificate error.我收到以下错误,有时我收到无效证书错误。

The SMTP server requires a secure connection or the client was not authenticated. SMTP 服务器需要安全连接或客户端未通过身份验证。 The server response was: 5.7.1 Client was not authenticated.服务器响应为:5.7.1 客户端未通过身份验证。

I am also getting this error我也收到这个错误

在此处输入图片说明 I think the problem is with Authentication, how can I force to use NTLM我认为问题出在身份验证上,如何强制使用 NTLM

I talked with the IT team they installed a tool on my pc to check email, using that tool email was sent successfully.我与 IT 团队交谈,他们在我的电脑上安装了一个工具来检查电子邮件,使用该工具电子邮件已成功发送。

The following are the setting which he applied in that tool以下是他在该工具中应用的设置

在此处输入图片说明

Can someone please help有人可以帮忙吗

我正在测试,我遇到了同样的问题,我通过禁用 SSL 安全来修复它

SC.EnableSsl = false; 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM