Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:52:24+00:00 2026-06-07T19:52:24+00:00

Does .NET 4 has any problems in sending emails? I had a .NET 3.5

  • 0

Does .NET 4 has any problems in sending emails? I had a .NET 3.5 solution and it was working then migrated the solution to .NET 4 and It does not works; nothing changed!

Notes:
I get this exception:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at …

And this is my code:

public static void SendEmail(
    this Email email)
{
    if (email.MailingSettings == null) throw new ArgumentNullException("email.MailingSettings", "specify email.MailingSettings");

    var settings = email.MailingSettings;

    if (string.IsNullOrEmpty(email.Sender)) throw new ArgumentException("email.Sender", "specify a sender");
    if (email.Recipients == null) throw new ArgumentNullException("email.Recipients", "specify at least a recipient");
    if (email.Recipients.Length == 0) throw new ArgumentNullException("email.Recipients", "specify at least a recipient");
    if (string.IsNullOrEmpty(settings.SMTPHost)) throw new ArgumentException("email.SMTPHost", "specify email.SMTPHost");

    var mail = new MailMessage();

    if (string.IsNullOrEmpty(email.SenderDisplayName))
        mail.From = new MailAddress(email.Sender);
    else
        mail.From = new MailAddress(email.Sender, email.SenderDisplayName);

    if (!string.IsNullOrEmpty(email.ReplyTo))
    {
        if (string.IsNullOrEmpty(email.ReplyToDisplayName))
        {
            mail.ReplyToList.Add(new MailAddress(email.ReplyTo));
        }
        else
        {
            mail.ReplyToList.Add(new MailAddress(email.ReplyTo, email.ReplyToDisplayName));
        }
    }

    foreach (string recipient in email.Recipients)
        mail.To.Add(new MailAddress(recipient));

    mail.Subject = email.Subject;
    mail.Body = email.Body;
    mail.IsBodyHtml = settings.IsBodyHtml;

    if (email.CC != null && email.CC.Length > 0)
        foreach (string cci in email.CC)
            mail.CC.Add(cci);

    if (email.BCC != null && email.BCC.Length > 0)
        foreach (string bcci in email.BCC)
            mail.Bcc.Add(bcci);

    if (email.Attachments != null)
        foreach (var ifn in email.Attachments)
            mail.Attachments.Add(
                new Attachment(
                    new MemoryStream(
                        ifn.Content),
                    ifn.FileName));

    var smtpPort = settings.SMTPPort > 0 ? settings.SMTPPort : 25;

    var smtpClient = new SmtpClient(settings.SMTPHost, smtpPort);
    smtpClient.EnableSsl = settings.EnableSsl;

    if (!string.IsNullOrEmpty(settings.SMTPUser))
    {
        smtpClient.UseDefaultCredentials = false;

        var smtpPassword = settings.SMTPPassword == null ? string.Empty : settings.SMTPPassword;

        NetworkCredential netCred;
        if (string.IsNullOrEmpty(settings.SMTPDomain))
            netCred = new NetworkCredential(settings.SMTPUser, smtpPassword);
        else
            netCred = new NetworkCredential(settings.SMTPUser, smtpPassword, settings.SMTPDomain);

        smtpClient.Credentials = netCred;
    }
    else
        smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;

    smtpClient.Timeout = 180 * 1000;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

    ServicePointManager.ServerCertificateValidationCallback =
        delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        { return true; };

    smtpClient.Send(mail);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:52:26+00:00Added an answer on June 7, 2026 at 7:52 pm

    This code is correct and works. The problem was on GMail side and solved (not detected why and how).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does C++ has some built in timer class with same idea as .NET System.Threading.Timer
Does anyone know if this has been released yet? I went to asp.net and
Does .NET natively support anything similar to PHP's variable variables ? If not, how
Does .NET 3.5 provide any build-in support for charts and graphs for Windows Forms
Does .Net have any built in constants for common numbers like million, billion etc?
Does .net framework 2.0 contain crystal report dlls or not? I am using vs
Does anyone know if there's any particular reason that VB.NET construct syntax isn't consistent?
Does anyone have any problems with Page_Load being executed twice in Google Chrome? It's
I have an application written in .NET. The previous version had no problems: you
I have a Windows forms project (VS 2005, .net 2.0). The solution has references

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.