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
- Login to the GMail account that will be sending out emails.
- Navigate to your account settings.
- In the search bar, type in "app pass" and select the dropdown option "App passwords"
- Type in an app name to identify the app password and click create.
- A window will appear with the automatically generated password. Copy and store the password somewhere secure.
- Once you close the popup window, you won't be able to see the password again.
- If you forget the password, you will need to generate a new one.
- 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)or465 (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.
- Make note of the recipient phone number's provider.
- Find that provider's SMS endpoint.
- This CSV File has a large set of endpoints, but it is old and might be outdated.
- Here's another link
- Send your SMS message as an E-Mail to the recipient E-Mail to SMS gateway, i.e.:
1234567890@txt.att.com