check smtp from commnad line

telnet smtp command line image

When working with Linux servers, you need to get mails from them,
they like to alert you on different issues like “help – im dying from lack of space” etc.

mail forwarding

you can easily setup mail forwarding in your sendmail through an external mail server.
all the sendmail config files are in /etc/mail.
edit the mailertable file and add a line like this:

domain    smtp:company_mail_server

for example – lets say you work for data.com and you want to send mails to the data.com domain from your Linux machine through the data.com mail server which is called mail.data.com, so your line in mailertable should be:

data.com    smtp:mail.data.com

test mail

to check that your company mail server will actually allow you to forward mails through it, you need to connect to the smtp service and try to send a mail, this will work from the command line:

telnet mail.data.com 25

this will try to connect to the mail server smtp port and if there is no firewall problem then you should see something like 220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8 as a reply.

at this point you try to send a mail through the server.

send mail from command line

telnet to the machine and copy paste this text after editing it:

helo domain_name
mail from: test@email
rcpt to: test@email
data
From: test@email
Subject: subject
whatever you want the mail to have in the body.
.

(the “.” in the end will finish the mail – dont forget it).

so lets explain:
helo domain_name – change the domain_name to your domain – data.com for example
mail from: the email you want the mail to look like it was sent from – test@data.com
rcpt to: who you want to get this test mail – admin@data.com
so the new updated test text would look like:

helo data.com
mail from: test@data.com
rcpt to: admin@data.com
data
From: test@data.com
Subject: test mail from command line
this is test number 1
sent from linux box
.

if there arent any permissions issues the mail server should show you something like: 250 2.0.0 n4CNnNPG003499 Message accepted for delivery

mail queue

there is another nice command line tool to show you whats your Linux server current mail queue: mailq:

[root@centos mail]# mailq
/var/spool/mqueue (1 request)
—–Q-ID—– –Size– —–Q-Time—– ————Sender/Recipient———–
n4CNnNPG003499        0 Wed May 13 02:49 test@email
(host map: lookup (email): deferred)
test@email
Total requests: 1

Technorati Tags: , ,

2 thoughts on “check smtp from commnad line”

  1. swaks (Swiss Army Knife SMTP, http://jetmore.org/john/code/swaks) is an extremely comfortable tool to test SMTP implementations. I personally just do `swaks -s -t ` and it will automatically generate a comfortable message body & subject for debugging purposes.

    And with that, some flamebait, sendmail is the root of all evil =) I like exim.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>