You are here

How to Install a Simple SMTP Client (ssmtp) on Ubuntu for Sending Emails from Your Website


How to Install a Simple SMTP Client (ssmtp) on Ubuntu for Sending Emails from Your Website

In this blog post, we'll guide you through the simple and speedy process of setting up an SMTP client on your Ubuntu system. This SMTP client will enable you to connect seamlessly to Yandex's email servers, allowing you to send emails from your website with ease. While many recommend using more robust solutions like Postfix or Sendmail, we believe that for tasks such as sending emails on behalf of a single user, such as website registration and notifications, simpler options like ssmtp are more efficient. Ssmtp is lightweight, easy to configure, supports encryption, and gets the job done exceptionally well.

Let's dive in.

Setting Up ssmtp on Ubuntu:

Step 1: Installing ssmtp

To begin, open your terminal and install ssmtp with the following command:

sudo apt-get install ssmtp

Step 2: Configuring ssmtp

Now, let's configure ssmtp by editing its configuration file. Open the configuration file with the following command:

 

sudo nano /etc/ssmtp/ssmtp.conf

In this file, make the necessary edits as shown below:

 

# Email address used as sender
[email protected]
# Domain from which the emails will appear to come
rewriteDomain=mytechnote.ru
# Yandex server and port
mailhub=smtp.yandex.ru:465
# Your server's hostname
hostname=mytechnote.ru
# Enable TLS encryption
UseTLS=YES
# Yandex authentication
[email protected]
AuthPass=yourpassword
# Allow users to customize the "From" field
FromLineOverride=YES

Step 3: Editing revaliases File

Next, edit the revaliases file with the following command:

sudo nano /etc/ssmtp/revaliases

Add lines like these to the file:

 

root:[email protected]:smtp.yandex.ru:465
www.mytechnote.ru:[email protected]:smtp.yandex.ru:465
www-data:[email protected]:smtp.yandex.ru:465

As you can see, the first field is the username, the second is the "From" field, and the third is the SMTP server and port.

 

Step 4: Testing Your Configuration

To test your setup, try sending an email using the following command:

ssmtp [email protected]
# When prompted, provide the following details:
To: [email protected]
From: [email protected]
Subject: test
# there should be one empty string

test

After typing the message, press Ctrl+D to send it. Your email should be sent successfully.

With ssmtp, setting up a lightweight SMTP client for your website on Ubuntu is a breeze. Its simplicity, ease of configuration, encryption support, and efficiency make it an ideal choice for tasks like website registration and notifications.

I have a video related to the topic:

0 0

Share the article with your friends in social networks, maybe it will be useful to them.


If the article helped you, you can >>thank the author<<