How to send mail via ssmtp
SSMTP (Simple SMTP) is a lightweight and easy-to-use SMTP server that allows you to send emails from your Linux system. Here's a step-by-step guide on how to send mail via SSMTP:
Prerequisites:
- Install SSMTP on your Linux system. The package name may vary depending on your distribution:
- Ubuntu/Debian:
sudo apt-get install ssmtp
- Red Hat/CentOS:
sudo yum install ssmtp
- Fedora:
sudo dnf install ssmtp
- Ubuntu/Debian:
- Configure your email account settings:
- You'll need to know your email account's SMTP server address, username, and password.
Configuring SSMTP:
- Edit the SSMTP configuration file:
sudo nano /etc/ssmtp/ssmtp.conf
- Update the following settings:
mailhub
: Set this to your email provider's SMTP server address (e.g.,smtp.gmail.com
for Gmail).FromLineOverride
: Set this toYES
to override the default "From" address.AuthUser
andAuthPass
: Set these to your email account's username and password, respectively.
- Save and exit the editor.
Sending an email using SSMTP:
- Use the
ssmtp
command to send an email:ssmtp -v [email protected] "Subject: Test email" "Body of the email"
- Replace
[email protected]
with the recipient's email address, andSubject
andBody
with your desired subject and message. - The
-v
flag enables verbose mode, which can help you troubleshoot any issues.
- If everything is configured correctly, you should receive the email at the specified recipient's address.
Tips and Variations:
- To send an email with a specific "From" address, use the
-f
flag followed by the desired "From" address:ssmtp -f [email protected] [email protected] "Subject: Test email" "Body of the email"
- To send an email with attachments, use the
-a
flag followed by the path to the attachment file:ssmtp -a /path/to/attachment [email protected] "Subject: Test email" "Body of the email"
- To send an email with a specific SMTP port, use the
-p
flag followed by the desired port number:ssmtp -p 587 [email protected] "Subject: Test email" "Body of the email"
Remember to replace the placeholders with your actual email account settings and recipient information. If you encounter any issues, refer to the SSMTP documentation or seek help from your email provider's support team.