A Complete Guide to Sending Emails with a Web-based Application

ASP.NET, PHP, Tutorials

An old programmer’s saying, coined by Jamie Zawinski, says “Every program attempts to expand until it can read mail”. Jokes aside, email was and still is an integral part of our lives, and every web application needs to send emails to its users. This guide will walk you through all the steps to ensure every single email-sending aspect is covered.

This is going to be a long article and we plan to update it often. Here are the topics, that will be covered in this article.

  • Setting up an SMTP account (Gmail)
  • Ensuring Deliverability
  • Sending Mass Emails
  • Sending emails via API
  • Transactional emails
  • Receiving emails

Setting up an SMTP account (Gmail)

Let’s start with the very basics. Here we will show how to create a new Gmail account and use it to send emails in your web application. All these steps are important.

1. Create a new Gmail account

Sign up for Gmail account.

2. Logon once via the web browser

This is also important. It activates your account.

3. Turn off 2FA

Two-factor authentication is for interactive logins. Our web application won’t know how to do this.

4. Create an app-specific password

This password will be used only in this specific web application. Here is the article that explains how to create such a password.

5. SMTP settings

– Server address: smtp.gmail.com

– Port:

  • If you’re using SSL, enter 465.
  • If you’re using TLS, enter 587.

– Username: your Gmail email i.e. yourname@gmail.com

– Password: app-specific password created on step 4.

Now your app should be ready to send emails via a newly created Gmail account. Give it a try.

6. If something still doesn’t work

If you use PHPRunner to build your web application, check this troubleshooting technique. It will show the whole dialog between the PHP code and the mail server and often will point you in the right direction.

If you use something else to build your web app, there is one more trick to try. Log on to Gmail on your desktop again. Once in a while, Gmail will block your web application for no apparent reason and you will see a warning like this after the login.

Once you click ‘Check activity’ you will see the screen like this one:

Confirm ‘It was me’ and try sending the email from your web application again. It should work.

2 thoughts on “A Complete Guide to Sending Emails with a Web-based Application

  1. If you enable two-factor authentication and create app passwords, Gmail will work like a charm without security alerts

  2. You have a great product, but I am sorry, but did I miss something here. On the outline it lists the following:
    Setting up an SMTP account (Gmail)
    Ensuring Deliverability
    Sending Mass Emails
    Sending emails via API
    Transactional emails
    Receiving emails

    I only see “Setting up and SMTP account (Gmail) in the article.

Leave a Reply

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