In this tutorial we’ll use the terminal to send email using SMTP. This method can be used to test the SMTP credentials by sending a test email.
Before you start#
- You’ll need a UNIX based terminal with openssl installed.
- SMTP credentials from any service like Gmail, AWS SES, Mailchimp etc. We’ll use Gmail credentials in this example
Encode the SMTP credentials#
Base64 encode the SMTP username and password (password will be app password for gmail). Copy the result of each of the commands.
echo -n "<username>" | openssl enc -base64
echo -n "<password>" | openssl enc -base64
Creating the email body#
Create a file named mail.txt with the following content.
EHLO example.com
AUTH LOGIN
<base64 username>
<base64 password>
MAIL FROM: [email protected]
RCPT TO: [email protected]
DATA
From: Sender Name <[email protected]>
To: [email protected]
Subject: Did it work?
This message was sent using the terminal.
.
QUIT
Replace [email protected] with your gmail id and [email protected] with the email id you want to send the message.
Sending the email#
Run the following command to send the email.
openssl s_client -crlf -quiet -starttls smtp -connect <email server>:<port> < /path/to/mail.txt
Replace your mail server host and port provided to you by the service.
Check your receiver mailbox.
Congratulations!🎉 You’ve successfully sent email from the terminal.