Finding Your Mail Server

This list of common mail servers might be helpful. If that doesn’t clear things up, then you can guess at your mail server.

First, find your real IP address as the outside world knows it. I’m using the website my-i-p.com here on the command line but you can just put it in a normal browser if that’s convenient:

$ lynx -dump my-i-p.com | grep "My ip address"

Find out who your ISP is with reverse lookup:

:-> [prince][~]$ nslookup 76.124.159.147 | grep name
147.159.124.76.in-addr.arpa name = c-76-124-159-147.hsd1.nj.comcast.net.

Guess what the mail server might be:

:-> [prince][~]$ nc smtp.comcast.net 25

If that works and you get a mail server greeting message, you are ready to interact with it to test it.

Explicit Mail Server Test

The first thing you need to do is verify you have a cooperating mail server. This process allows you to check on the functionality of a putative mail server from the command line with no ambiguity.

220 OMTA11.westchester.pa.mail.comcast.net comcast ESMTP server ready
HELO just setting up my mail and testing the server
250 OMTA11.westchester.pa.mail.comcast.net hello [76.124.159.147],
pleased to meet you
MAIL FROM: xampl@example.xed.ch
250 2.1.0 <xampl@example.xed.ch> sender ok
RCPT TO: example@gmail.com
250 2.1.5 <example@gmail.com> recipient ok
DATA
354 enter mail, end with "." on a line by itself
This is a test message from a comcast server.
.
QUIT

Ubuntu

By default Ubuntu seems to not support non local email.

One easy solution to send things is sendEmail:

$ sudo apt-get install sendemail
$ sendEmail -f xampl@example.xed.ch -t example@gmail.com -u "Test message of sendEmail on pr" -s smtp.comcast.net <<<"This is a test message."
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
    - First line must be received within 60 seconds.
    - End manual input with a CTRL-D on its own line.
May 15 13:39:36 prince sendEmail[21947]: Message input complete.
May 15 13:39:37 prince sendEmail[21947]: Email was sent successfully!

This is a good way to test the server for the next level of curing this problem described below.

Here’s how to fix it properly:

$ sudo apt-get install msmtp mailx
$ sudo dpkg-reconfigure exim4-config
 internet site; mail is sent and received directly using SMTP
 mail name= example.xed.ch
 listen on= 127.0.0.1 (unless you really want outside mail traffic)
 recipient domains= <empty>
 recipient relay= <empty>
 uncond relay= <empty>
 DNS minimal= No
 delivery format= mbox
 split config= No
 aliases for postmaster and root= "xed postmaster-pr@example.xed.ch"

Then create this file /etc/msmtprc containing:

account cox
host smtp-server.san.rr.com

account default : cox

Or:

account comcast
host smtp.comcast.net

account default : comcast

Now test:

$ mail -s "test of pr exim cli mail" example@gmail.com <<<"This is a test `date`"

And troubleshoot:

$ cat /var/log/exim4/mainlog

Email With Gentoo

Packages Relevant For Email

mail-mta/sendmail

Widely-used Mail Transport Agent (MTA).

mail-mta/postfix

A fast and secure drop-in replacement for sendmail.

mail-client/mailx

The /bin/mail program, which is used to send mail via shell scripts.

mail-mta/ssmtp

Extremely simple MTA to get mail off the system to a Mailhub

mail-mta/msmtp

An SMTP client and SMTP plugin for mail user agents such as Mutt.

net-mail/sendEmail

Command line based, SMTP email agent.

net-mail/email

Advanced CLI tool for sending email.

Note
mail-client/mailx is important for command line /bin/mail to work with the MTA that is installed (sendmail, postfix, etc).

A Simple Homemade Mail Client

xed_mutt_puppy.py
#!/usr/bin/python
# Here is a quick and dirty mail client designed to just see mail.
# This was written when the route between my house and mail server was
# blocked for some weird reason. I was able to use this on an ssh
# account to look at some critical mail.
import getpass, imaplib

theuser= 'xed'
thepass= getpass.getpass()
mail_server= 'mail66.theisp.com'

#M= imaplib.IMAP4()
M= imaplib.IMAP4_SSL(mail_server)

M.login(theuser, thepass)

M.select()

typ, data= M.search(None, 'ALL')

for num in data [0].split():
    typ, data = M.fetch(num, '(RFC822)')
    print 'Message %s\n%s\n' % (num, data[0][1])

M.close()

M.logout()