Suppose i send a mail using the following the following command:

mailx person@x.com

then does mailx first try to find out the SMTP server of my ISP for relaying the mail or does it connect directly. Does it depend on whether my PC has a public IP address or it is behind a NAT. How do I check the settings of mailx on my PC? How can I verify this using tcpdump?

link|improve this question

68% accept rate
feedback

4 Answers

up vote 2 down vote accepted

Normally, mail and derivatives (and almost any other Unix MUA) use the traditional sendmail interface - /usr/bin/sendmail, provided by almost all MTAs (postfix, exim, sendmail, courier). This is the traditional Unix way.

Once a message is submitted through sendmail, your MTA handles message transmission. Depending on configuration, it may either connect directly to the destination MTA (if on a server), or relay mail through another host (also called a smarthost) - the latter is more common on personal computers, where relaying through your Gmail or ISP/work email account is essential.

(Some MTAs such as esmtp or nullmailer are built specifically for home users and always use a relayhost. These don't support receiving mail and are a lot lighter on resources.)

mailx → /usr/bin/sendmail → local MTA → recipient MTA → recipient inbox
mailx → /usr/bin/sendmail → local MTA → Gmail or ISP/work servers → recipient MTA → recipient inbox

Other programs (mostly the user-friendly graphical clients such as Thunderbird or Outlook) connect directly to a relay SMTP server (again, usually Gmail or ISP/work SMTP server), which transmits the message further.

SMTP support is present in heirloom-mailx, but not in the traditional bsd-mailx.

app → Gmail or ISP/work servers → recipient MTA → recipient inbox

The third method - directly to recipient's server - is almost never used, and no MUA supports it. On personal computers, using it would cause your message to get rejected (a lot of spam is sent from infected home user IP addresses).

link|improve this answer
how to find out my MTA on linux? – iamrohitbanga May 4 '10 at 17:03
why should outlook send through a relay SMTP server? If i am sending a mail to iamrohitbanga@gmail.com then it should directly contact mail server for gmail which is the destination mail server and not the relay server? right or wrong? – iamrohitbanga May 4 '10 at 17:06
why do you use Gmail or ISP/work servers together? suppose I am sending from a@b.com to c@d.com shouldn't the sequence be app->b->d->recipient inbox. – iamrohitbanga May 4 '10 at 17:08
did not understand third method. when i send using mailx iamrohitbanga@gmail.com, no mail lands up in my inbox and no mailer daemon notification is returned. why did my message disappear? For my organizations mail server however i do get a message saying that mail was not delivered as name could not be resolved. Why is that so? I remember that I used mailx to send messages this way on another system. Is there a configuration problem? – iamrohitbanga May 4 '10 at 17:09
@iamrohitbanga 1) Check the list of installed packages. (Not all distros come with a MTA by default.) – grawity May 4 '10 at 17:10
show 12 more comments
feedback

mailx can use SMTP. It's configure file is ~/.mailrc

One example is mailx using Gmail's SMTP.

The configure can even be in one command:

mailx -v -s "$EMAIL_SUBJECT" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://smtp.gmail.com:587 \
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
-S smtp-auth-user=$FROM_EMAIL_ADDRESS \
-S smtp-auth-password=$EMAIL_ACCOUNT_PASSWORD \
-S ssl-verify=ignore \
-S nss-config-dir=~/.mozilla/firefox/xxxxxxxx.default/ \
$TO_EMAIL_ADDRESS

If a normal SMTP server is used, it is much easier:

mailx -v -s "$EMAIL_SUBJECT" \
-S smtp=smtp://smtp.server.com
-S from="$FROM_EMAIL_ADDRESS($FRIENDLY_NAME)" \
$TO_EMAIL_ADDRESS
link|improve this answer
Note that this depends on heirloom-mailx which is not the default mailx. – Scott Apr 5 at 2:37
@Scott: Yes. But depends on the Linux distribution. On some systems, the default is not heirloom (e.g. Ubuntu: fclose.com/b/linux/1411/… . seems there are 3 mailx versions). On some other ones such as Fedora, OpenSUSE, the default one is the "feature riched" "heirloom-mailx". – Zhiqiang Ma Apr 16 at 9:41
feedback

From the mailx(1) man page, DESCRIPTION section, String Options subsection:

   smtp   Normally, mailx invokes sendmail(8) directly to  transfer
          messages.  If the smtp variable is set, a SMTP connection
          to the server specified by the value of this variable  is
          used  instead.
link|improve this answer
this confused me a bit. can you be more elaborate. – iamrohitbanga May 4 '10 at 14:18
Uhh... it uses sendmail unless this option is set. – Ignacio Vazquez-Abrams May 4 '10 at 14:41
feedback
echo this is my message | mail -sSubject -Ssmtp=smtp.east.cox.net youraddress@yourhost.com
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.