How to Send an Email using Telnet

We’ll be using telnet to connect to a mail server and send ourselves an email.

The parts in bold are the commands to enter.

[bob@linux ~]$ telnet 25
Connected to
Escape character is '^]'. ESMTP Exim 4.85 #2 Mon, 09 May 2022 22:12:59 
220-We do not authorize the use of this system to transport unsolicited, 
220 and/or bulk e-mail.
250 Hello []
250 OK
250 Accepted
354 Enter message, ending with "." on a line by itself
Subject: Test Message

This is a test

250 OK id=5a1g7i-1347MT-1p
221 closing connection
Connection closed by foreign host.

Further links to read

Exim Bulk Remove Email Messages in Queue

exim -bp | grep "string" -A1 | awk {'print $3'}

Replace string with the email address, or domain you want to search for and delete.
Note that -A1 may not be needed. Grep will just search for string and 1 line after it. I had a problem with the string I was wanting to use was on the line below it

imapsync bulk copy not copying first account in list

Ran into an issue where it looked like imapsync would fail to connect to the server on the first line when trying to do a bulk move.;;password1;;;password2

Was able to work around the issue by Adding a comment line to the top of the file. May have to do with how the script I was using handles the lines.

### Email Import list;;password1;;;password2

Script used to copy

# $Id:,v 1.6 2015/11/04 18:23:04 gilles Exp gilles $ 
#Example for imapsync massive migration on Unix systems.
#See also
Data is supposed to be in file.txt in the following format:
host001_1;user001_1;password001_1;host001_2;user001_2;password001_2; … 
#Separator is character semi-colon ";" it can be changed by any character changing IFS=';' in the while loop below.
# Each line contains 6 columns, columns are parameter values for
--host1 --user1 --password1 --host2 --user2 --password2
and a trailing empty fake column to avoid CR LF part going
in the 6th parameter password2. Don't forget the last semicolon.
# You can add extra options after the variable "$@" Use character backslash \ at the end of each supplementary line, xcept for the last one. You can also pass extra options via the parameters of this script since they will be in "$@" The credentials filename "file.txt" used for the loop can be renamed by changing "file.txt" below. echo Looping on account credentials found in file.txt
{ while IFS=',' read  h1 u1 p1 h2 u2 p2 fake
        { echo "$h1" | egrep "^#" ; } > /dev/null && continue # this skip commented lines in file.txt
        echo "==== Starting imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
         imapsync --host1 "$h1" --user1 "$u1" --password1 "$p1" \
                  --host2 "$h2" --user2 "$u2" --password2 "$p2" \
                  "$@" --delete2
         echo "==== Ended imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
} < ${file}

imapsync – NO [OVERQUOTA] Not enough disk quota

msg INBOX/4624 {75129} couldn't append  (Subject:[Email message]) to folder INBOX: Error sending '55 APPEND INBOX (\Seen) "25-Aug-2017 09:12:05 -0600" {75129}': 55 NO [OVERQUOTA] Not enough disk quota (0.001 + 0.000 secs).

To resolve the above problem, check the following

  1. Email mailbox allocated size
  2. cPanel account user Quota

The above problem was due to the fact that the cPanel User Quota was maxed out. Increasing the space allocated to the account resolved the problem.

Cannot open mailbox /var/mail/pi: Permission denied

This is on a Raspberry Pi, but should be the same on any Linux distro.

Error :

pi@raspberrypi:~ $ mail
Cannot open mailbox /var/mail/pi: Permission denied
No mail for pi
pi@raspberrypi:~ $ 

Fix :

sudo touch /var/mail/$USER
sudo chown $USER:mail /var/mail/$USER
sudo chmod 660 /var/mail/$USER

You can replace “$USER” if you need to run the commands for a different account.

sudo touch /var/mail/pi
sudo chown pi:mail /var/mail/pi
sudo chmod 660 /var/mail/pi