Send Email from Asp.Net Application using Google Account and SMTP

In order to send mail from the application we can use SMTP server from Google (which off course has certain limitations). We can use a Google mail account and send the mail using SMTP server from Google. This works very well for applications which need to use a simple form such as “Contact Us”. An example of this is explained below. We will use AJAX to send the request to an ASP.Net web service which sends the mail from the server side.

Create a web service as following

In order for the method to be called using AJAX make sure to uncomment [System.Web.Script.Services.ScriptService] in the web service code.

Add following appsettings in web.config

Change values and replace email and password to your account credentials. Leave SMTPhost and port as-is.

We will now create a simple HTML page to input the data

Now the last piece is to simply call the web service by passing required data for the email

You can download complete code (along with solution package) here.

If you get an error, it might be possible that Google blocked it. You need to ensure that the setting to allow less secure apps is turned on

Leave A Comment

Your email address will not be published. Required fields are marked *