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

  • Home
  • SEARCH
  • 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 7753249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:00:39+00:00 2026-06-01T12:00:39+00:00

Setting up email details in web.config – but no email is being sent! <appSettings>

  • 0

Setting up email details in web.config – but no email is being sent!

  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="smtpServer" value="smtp.live.com" />
    <add key="EnableSsl" value = "true"/>
    <add key="smtpPort" value="587" />
    <add key="smtpUser" value="MyEmail@live.co.uk" />
    <add key="smtpPass" value="mypasswordgoeshere" />
    <add key="adminEmail" value="no-reply@no-reply.com" />
  </appSettings>

I am using the following class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Configuration;

namespace MVCcars.Utils
{
  public static class MailClient
  {
    private static readonly SmtpClient Client;
    static MailClient()
    {
      Client = new SmtpClient
      {
        Host =
          ConfigurationManager.AppSettings["SmtpServer"],
        Port =
          Convert.ToInt32(
            ConfigurationManager.AppSettings["SmtpPort"]),
        DeliveryMethod = SmtpDeliveryMethod.Network

      };
      Client.UseDefaultCredentials = false;
      Client.Credentials = new NetworkCredential(
      ConfigurationManager.AppSettings["SmtpUser"],
      ConfigurationManager.AppSettings["SmtpPass"]);
    }


    private static bool SendMessage(string from, string to,
      string subject, string body)
    {
      MailMessage mm = null;
      bool isSent = false;
      try
      {
        // Create our message
        mm = new MailMessage(from, to, subject, body);
        mm.DeliveryNotificationOptions =
        DeliveryNotificationOptions.OnFailure;
        // Send it
        Client.Send(mm);
        isSent = true;
      }
      // Catch any errors, these should be logged and
      // dealt with later
      catch (Exception ex)
      {
        // If you wish to log email errors,
        // add it here...
        var exMsg = ex.Message;
      }
      finally
      {
        mm.Dispose();
      }
      return isSent;
    }


    public static bool SendWelcome(string email)
    {
      string body = "Put welcome email content here...";
      return SendMessage(
        ConfigurationManager.AppSettings["adminEmail"],
          email, "Welcome message", body);
    }
  }
}

This is the Account controller:

[HttpPost]
public ActionResult Register(RegisterModel model)
{
    if (ModelState.IsValid)
    {
        // Attempt to register the user
        MembershipCreateStatus createStatus;
        Membership.CreateUser(model.UserName,
          model.Password, model.Email, null, null,
          true, null, out createStatus);
        if (createStatus ==
            MembershipCreateStatus.Success)
        {
          // Send welcome email
          MailClient.SendWelcome(model.Email);
          FormsAuthentication.SetAuthCookie(
            model.UserName,
            false /* createPersistentCookie */);
          return RedirectToAction("create", "Customer");
        }
        else
        {
          ModelState.AddModelError("",
            ErrorCodeToString(createStatus));
        }
    }
    // If we got this far, something failed,
    // redisplay form
    return View(model);   
}

Are the app settings in the web.config right for the enableSsl?
any advice welcome

  • 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-01T12:00:41+00:00Added an answer on June 1, 2026 at 12:00 pm

    An even easier way to work with the SmtpClient in .NET is to use the system.net configuration settings. This will allow you to set the defaults for any SmtpClient that is created without having to write code to set all of the properties. This way you can easily modify the entire setup without changing any code.

      <system.net>
        <mailSettings>
          <smtp from="no-reply@no-reply.com">
            <network host="smtp.live.com" password="mypasswordgoeshere" port="587" userName="MyEmail@live.co.uk"  enableSsl="true"/>
          </smtp>
        </mailSettings>
      </system.net>
    

    And then in code

     System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
     smtp.Send(mailMessage);
    

    EDIT Here’s the orginal code I posted below:

    static MailClient() 
    { 
         Client = new SmtpClient 
         { 
             Host = ConfigurationManager.AppSettings["SmtpServer"], 
             Port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]), 
             DeliveryMethod = SmtpDeliveryMethod.Network,
             EnableSsl = bool.Parse(ConfigurationManager.AppSettings["EnableSsl"])
    
         };
      .....
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MFMailComposeViewController for compose the email. But what's the API for setting up email account?
I'm seeking advice about setting up an email gateway so students can email me
I'm programmatically sending HTML-formatted email, and setting the font as Arial throughout ( font-family:
I'm using JavaMail to send email requests to an SMTP server. I'm setting both
I send an email from my smtp server, for example, setting From to anyemail@anydomain.com
Currently sending emails and setting the Return-path of an email(System.Net.Mail) works if i put
For my Perl web application, I need account verification via email. I already have
I am learning to how send email with Rails 3 with Agile Web Development
I have configured my email.yml in my Redmine installation, but when I try to
I'm looking Jquery UI's modal form demo . But i want to add something.

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.