Click here to Skip to main content
15,991,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting exception "
a call to SSPI failed,  The function requested is not supported
" during mail sending process in c#. Code used for sending mail is shared below.

What I have tried:

Mail sending code is as below:
rivate bool SendMail(string fromMail, string senderName, string toMail, string mailContent, string subject)
    {
        bool result = true;
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        try
        {
            MailAddress fromAddress = new MailAddress(fromMail, senderName);

            // You can specify the host name or ipaddress of your server
            // Default in IIS will be localhost 
            smtpClient.Host = ConfigurationManager.AppSettings["SMTPServer"];

            //Added by Alex on 20240625 for sending mail with TLS (Mantis Id-1859) Start 
            string SMTPServerSSLFlag = ConfigurationManager.AppSettings["SMTPServerSSLFlag"] != null ? Convert.ToString(ConfigurationManager.AppSettings["SMTPServerSSLFlag"].ToString()) : "0";
            if (SMTPServerSSLFlag == "1")
            {
                smtpClient.EnableSsl = true;
            }
            //Added by Alex on 20240625 for sending mail with TLS (Mantis Id-1859) End 
            //Default port will be 25
            smtpClient.Port = 25;

            //From address will be given as a MailAddress Object
            message.From = fromAddress;

            // To address collection of MailAddress
            message.To.Add(toMail);
            message.Subject = subject;

            // CC and BCC optional
            // MailAddressCollection class is used to send the email to various users
            // You can specify Address as new MailAddress("admin1@yoursite.com")
            //message.CC.Add("admin1@yoursite.com");
            //message.CC.Add("admin2@yoursite.com");

            // You can specify Address directly as string
            //message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
            //message.Bcc.Add(new MailAddress("admin4@yoursite.com"));

            //Body can be Html or text format
            //Specify true if it  is html message
            message.IsBodyHtml = true;

            // Message body content
            message.Body = mailContent;

            // Send SMTP mail
            smtpClient.Send(message);

            //Common.showMessage("e-Mail successfully sent.", this);
        }
        catch (Exception ex)
        {
            result = false;
        }
        return result;
    }
Posted
Updated 1-Jul-24 17:32pm
v2
Comments
ChandraRam 2-Jul-24 3:39am    
What is the SecurityProtocol set to?

1 solution

Transport Layer Security (TLS) best practices with .NET Framework | Microsoft Learn[^]

If you're using .NET Framework, make sure your code is build against .NET Framework 4.8, don't explicitly set the security protocols, and ensure the operating system is configured to connect using the same protocols that the mail server has enabled.

You will need to talk to the people who run the mail server to find out what protocols need to be enabled.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900