Configuring <mailsettings> In Web.config To Send Email

How Do I Configure the <mailSettings> Section in web.config to Send Email?

To send email from an ASP.NET website (such as a simple enquiry form), you must configure the <mailSettings> section inside your web.config file. This tells ASP.NET which SMTP server to use, along with your email login details.

Replace the example email address, SMTP hostname, and password with your own details.


Basic SMTP Configuration (Port 25)
<configuration>
  <system.net>
    <mailSettings>
      <smtp from="email@yourdomain.com">
        <network 
          host="mail.yourdomain.com" 
          port="25" 
          userName="email@yourdomain.com" 
          password="youremailpassword" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
        

Recommended Modern Configuration (TLS on Port 587)

Most mail servers now require authentication with TLS encryption:

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="email@yourdomain.com" deliveryMethod="Network">
        <network 
          host="mail.yourdomain.com" 
          port="587"
          enableSsl="true"
          userName="email@yourdomain.com"
          password="youremailpassword" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
        

Important Notes

  • email@yourdomain.com must be a real mailbox hosted on your domain.
  • mail.yourdomain.com should be your actual SMTP hostname.
  • Use port 587 + SSL/TLS whenever possible for best deliverability.
  • Ensure your domain has correct SPF, DKIM, and DMARC records.

Once configured, you can send email using SmtpClient or any ASP.NET mail library.


Learn More About Fast2host

Fast2host has been providing reliable UK hosting, domains, cloud servers and business email since 2002. Find out more about who we are:

About Fast2host →
Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 9372

Need more information or have a question ?