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 9084163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:56:16+00:00 2026-06-16T20:56:16+00:00

In my MVC4 application, I’m using the SmtpClient to send out email via Gmail’s

  • 0

In my MVC4 application, I’m using the SmtpClient to send out email via Gmail’s smtp.gmail.com SMTP server.

I’ve configured my Web.Config file with the following settings:

<system.net>
 <mailSettings>
  <smtp deliveryMethod="Network">
   <network enableSsl="true" 
   defaultCredentials="false" 
   host="smtp.gmail.com" 
   port="587" 
   userName="xxMyUserNamexx@gmail.com" 
   password="xxMyPasswordxx" />
  </smtp>
 </mailSettings>
</system.net>

The method that uses the SmtpClient and sends an email message looks like:

public void SendMail(string fromDisplayName, string fromEmailAddress, string toEmailAddress, string subject, string body)
{
    MailAddress from = new MailAddress(fromEmailAddress, fromDisplayName);
    MailAddress to = new MailAddress(toEmailAddress);
    MailMessage mailMessage = new MailMessage(from, to);
    mailMessage.Body = body;
    mailMessage.Subject = subject;

    SmtpClient client = new SmtpClient();
    //client.UseDefaultCredentials = false;
    client.Send(mailMessage);
}

The code above works as expected and is fine. What confuses me is the commented line client.UseDefaultCredentials = false; – If I were to uncomment that line, I’ll receive an exception message that states:

The SMTP server requires a secure connection or the client was not
authenticated. The server response was: 5.5.1 Authentication Required.

What’s more is, it doesn’t matter if I set the UseDefaultCredentials property to true or false, I’ll still receive the exception message. The only way for me to avoid the exception message is to remove the line altogether.

Is this behavior normal? Can you explain why I’m receiving the exception message?

  • 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-16T20:56:17+00:00Added an answer on June 16, 2026 at 8:56 pm

    So why would me explicitly setting the property to false throw an exception?

    The reason for this is because the setter for UseDefaultCredentials sets the Credentials property to null if you set it to false, or it sets it to the CredentialCache.DefaultNetworkCredentials property if set to true. The DefaultNetworkCredentials property is defined by MSDN as:

    The credentials returned by DefaultNetworkCredentials represents the authentication credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default network credentials are the user credentials of the logged-in user, or the user being impersonated.

    When you set UseDefaultCredentials to true, it’s using your IIS user, and I’m assuming that your IIS user does not have the same authentication credentials as your account for whatever SMTP server you’re using. Setting UseDefaultCredentials to false null’s out the credentials that are set. So either way you’re getting that error.

    Here’s a look at the setter for UseDefaultCredentials using dotPeek:

    set
    {
        if (this.InCall)
        {
            throw new InvalidOperationException(
                SR.GetString("SmtpInvalidOperationDuringSend"));
        }
        this.transport.Credentials = value 
            ? (ICredentialsByHost) CredentialCache.DefaultNetworkCredentials 
            : (ICredentialsByHost) null;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an Azure/MVC4 application using Visual Studio Web Developer 2010 Express, on a
I'm using SignalR in my mvc4 web application. I have a class inheriting from
I'm using EF 4.3 in an MVC4 application and Ninject.MVC3. Controllers are MVCscaffolded using
I have an MVC4 web application In setting it up on IIS7.5 I added
I am currently working on MVC4 SinglePage Application. I have a Web Api method
If you create a new MVC4 web application with the Internet Application Project Template
My web application is ASP.NET MVC4 with Razor and Knockout.js. The view model hierarchy
I have been writing an application using ASP.Net MVC4, where the majority of the
Hi i m using mvc4 application and using bundles to render scripts and css
I have an ASP.NET MVC4 application that is using jQuery to make some calls

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.