Skip to main content

Send E-Mails Programmatically with GMail

  • This document was written during the ESF project to send alarms via email and SMS.
  • The ESF application uses Opto, which is a relatively old piece of software (at least in terms of modern security and auth standards).
  • This, and other old security applications, require a special "app password" to be created for authenticating to GMail's servers.

Generate an App Password

  1. Login to the GMail account that will be sending out emails.
  2. Navigate to your account settings.
  3. In the search bar, type in "app pass" and select the dropdown option "App passwords"
  4. Type in an app name to identify the app password and click create.
  5. A window will appear with the automatically generated password. Copy and store the password somewhere secure.
    1. Once you close the popup window, you won't be able to see the password again.
    2. If you forget the password, you will need to generate a new one.
  6. Use this password when authenticating in a programmatic environment, such as from Opto Pac software (as in ESF project), or from a custom program/script.

Configure the Mailing Client to use GMail

There are countless potential clients for sending emails, so I will be using generic language to describe how to configure any number of them.

For GMail, the following settings should be used:

  • Server: smtp.gmail.com
  • Port: 587 (TLS) or 465 (SSL). Try TLS first, then SSL if TLS doesn't work.
  • Authentication will likely be "Basic".
    • Provide your email as the username.
    • Provide the App Password as the account's password.

Send SMS from E-Mail

You can send SMS from ANY email provider. These steps should be provider-agnostic.

  1. Make note of the recipient phone number's provider.
  2. Find that provider's SMS endpoint.
  3. Send your SMS message as an E-Mail to the recipient E-Mail to SMS gateway, i.e.: 1234567890@txt.att.com