Using curl as a smtp client to send an email

curl can be used to send a test email to a smtp server like this:

curl smtp://localhost:2525 --mail-from "test-sender@test.com" --mail-rcpt "test1@test.com" --upload-file test-email.txt

Where test-email.txt contains you test email content:

From: "User Name" <test-sender@test.com>
To: "Test1" <test1@test.com>
Subject: Test email 1

This is a test email

If you also add the -v verbose option for curl you can see the STMP exchange with the server:

* Host localhost:2525 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying [::1]:2525...
* Connected to localhost (::1) port 2525
< 220 af54c17beae6 smtp4dev ready
> EHLO test-email.txt
< 250-Nice to meet you.
< 250-8BITMIME
< 250-SIZE
< 250-SMTPUTF8
< 250-AUTH=CRAM-MD5 PLAIN LOGIN XOAUTH2
< 250 AUTH CRAM-MD5 PLAIN LOGIN XOAUTH2
> MAIL FROM:<test-sender@test.com> SIZE=114
< 250 New message started
> RCPT TO:<test1@test.com>
< 250 Recipient accepted
> DATA
< 354 End message with period
} [119 bytes data]
* upload completely sent off: 119 bytes
< 250 Mail accepted
104 114 0 0 104 119 0 2075 --:--:-- --:--:-- --:--:-- 2087
* Connection #0 to host localhost left intact

Mounting SMB and NFS shares from ugreen NAS on Linux

To mount an NFS share on Ubuntu:

sudo mount -t nfs4 ip-address=of-nas:/volume[x]/sharename /mnt/path

If you get this error:

mount: /mnt/path: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program

Install helpers (from here):

# for NFS
sudo apt install nfs-common

# for SMB
sudo apt install cifs-utils

For mounting an SMB share using a specific userid (will be prompted for password):

sudo mount -t cifs -o username=your-user-id //ip-address/sharename /mnt/path

Note for ugreen NAS shares, the sharename is just the sharename and not /volume[]x]/sharename

Creating and renewing Let’s Encrypt SSL certificates with certbot

After purchasing SSL certs for many years for my personal project websites, I recently switched to creating free Let’s Encrypt certs using CertBot instead.

To install with python and pip on Debian based Linux, for nginx (from here):

Install deps and install:

sudo apt install python3 python3-dev python3-venv libaugeas-dev gcc
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip

sudo /opt/certbot/bin/pip install certbot certbot-nginx
sudo ln -s /opt/certbot/bin/certbot /usr/local/bin/certbot

To generate certificate and renew manually (same command):

sudo certbot certonly -v --reinstall --webroot --webroot-path=/var/www/html/ --email your@email --agree-tos --no-eff-email -d your.domain.name

To view current status of your certificates:

certbot certificates

For websites not on the public internet where the validation step can’t use the webserver to host a validation file, certbot also can validate using a DNS record with a generated value – follow the prompts to use this approach:

certbot certonly --manual --preferred-challenges dns -d your.domain.name