简体   繁体   中英

Send Email in C# using NTLM

I need to send email using NTLM, currently, I'm using the following code to send email

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.

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. The server response was: 5.7.1 Client was not authenticated.

I am also getting this error

在此处输入图片说明 I think the problem is with Authentication, how can I force to use NTLM

I talked with the IT team they installed a tool on my pc to check email, using that tool email was sent successfully.

The following are the setting which he applied in that tool

在此处输入图片说明

Can someone please help

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

SC.EnableSsl = false; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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