A simple way for users to use a send-only sendmail emulator.
1. Operating System
Before you start, you need to have at lease one of these platforms in place
- Windows 10 using a Linux subsystem
- Ubuntu
- Linux
- Raspberry Pi
2. Google Account
- Login to your Gmail account
- Select Security.
- Under "Signing in to Google" select 2-Step Verification.
- At the bottom of the page, select App passwords.
- Enter a name that helps you remember where you’ll use the app password.
- Select Generate.
- To enter the app password, follow the instructions on your screen. The app password is the 16-character code that will be used for your email password in the python script.
- Select Done.
3. Open up your terminal
Enter these commands below
foo@bar:~$ sudo apt update && sudo apt upgrade
foo@bar:~$ sudo apt-get install ssmtp mailutils
foo@bar:~$ sudo apt-get install postfix
foo@bar:~$ sudo apt-get install ssmtp
4. Save original conf file
foo@bar:~$ sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak
5 . Create new conf file (with vi, or some other text editor)
foo@bar:~$ sudo vi /etc/ssmtp/ssmtp.conf
In your file content, apply these changes
root=your_account@gmail.com
mailhub=smtp.gmail.com:587
FromLineOverride=YES
AuthUser=your_account@gmail.com
AuthPass=your_password
UseSTARTTLS=YES
UseTLS=YES
# Debug=Yes
Now enter
ctrl o
y to save your file
ctrl x to exit
6. Secure conf file
foo@bar:~$ sudo groupadd ssmtp
foo@bar:~$ sudo chown :ssmtp /etc/ssmtp/ssmtp.conf
Now lets create a text file to create some content for our message!
foo@bar:~$ nano test.txt
In your file content, apply these changes
Hello 1 2 3
Now enter
ctrl o
y to save your file
ctrl x to exit
7. Last but not least, the test!
foo@bar:~$ ssmtp recipient.address@some_domain.com < test.txt
Added bonus
Try texting from your computer to your phone! Look at link 3 for your carrier gateway
foo@bar:~$ ssmtp 1234567890@smsgateway < test.txt
Try texting from your computer to your phone using shell!
foo@bar:~$ nano test.sh
#!/bin/bash
ssmtp ssmtp 1234567890@smsgateway < test.txt
echo "Message sent" #prints in console/terminal
Now enter
ctrl o
y to save your file
ctrl x to exit
foo@bar:~$ chmod 777 test.sh
foo@bar:~$ ./test.sh
Message sent
foo@bar:~$
Take your SSMTP messaging skills a bit further using the OpenWeatherMap API! After signing up for a free key, you can use my weatherapi.py script as a guide to get a weather report on your phone. The output for my code is
Weather Output
How to send mail from command line using gmail smtp server
How to write a shell script
SMS gateway lookup
Cell phone lookup
- What is ssmtp?
SSMTP is a send-only sendmail emulator for machines which normally pick their mail up from a centralized mailhub. - What is mailutils?
Mailutils is a swiss army knife of electronic mail handling and offers a set of utilities and daemons for processing e-mail. - What is postfix?
Postfix is a free open-source mail transfer agent (MTA) that routes and delivers electronic mail.