Email Setup Center
  • Home »
  • Configure Smtp Server To Send Email In Asp.Net

How To Configure Smtp Server and asp .net send email?

While writing the code for your website using asp.net, you might want to send emails from your web application. You can configure the SMPT server to asp .net send email. For this, you can write the function directly in your ASP.NET coding. But this may be tricky if you wish to change the credentials. Each time you wish to change the credentials, you may have to make a lot of changes.

So the better alternative option for this would be to configure the SMPT server settings in the Web.config file. In the Web.config file, you have to specify the SMTP server in the host element, the port for the SMPT server, the email address and the password. Also, you have to enable SSL if your email server uses SSL.

A sample Web.config file is given below. This sample file uses the Gmail SMTP server and has the configurations to set up the Gmail SMTP server.

  • configuration
  • system.net
  • mailSettings
  • smtp deliveryMethod=”Network”
  • network host=”smtp.gmail.com” enableSsl=”true” port=”587"
  • userName=”gmail_id” password=”your_password” />
  • smtp
  • mailSettings
  • system.net
  • configuration
how-to-configure-smtp-server-to-send-email-in-asp .net send email
  • Step 1:By using a Web.config file like this, you can just specify the mail body in the code and create an instance for the SmptClinet in your ASP.NET code.
  • Step 2:The instance will automatically refer to the Web.config file for the SMPT server configurations. Even if you want to change the configurations in the future, you can make the configuration settings in the Web.config file with ease if your asp .net send email is not received.