Email: Difference between revisions

adds mail test script
m Text replacement - "<(\/?)source" to "<$1syntaxhighlight"
 
(One intermediate revision by one other user not shown)
Line 12: Line 12:


Make sure your server IP is not blacklisted or firewalled.  [[Telnet]] to Google:
Make sure your server IP is not blacklisted or firewalled.  [[Telnet]] to Google:
<source lang="bash">
<syntaxhighlight lang="bash">
telnet smtp.gmail.com 25
telnet smtp.gmail.com 25
# then  
# then  
^] # get a telnet prompt with the Ctrl key plus right square bracket key
^] # get a telnet prompt with the Ctrl key plus right square bracket key
quit [enter]
quit [enter]
</source>
</syntaxhighlight>


So a successful test ends up looking like this:
So a successful test ends up looking like this:
Line 38: Line 38:
First, did you check if mail is working from PHP?
First, did you check if mail is working from PHP?


<source lang="php">
<syntaxhighlight lang="php">
<?php
<?php
     $mailto = 'greg@eQuality-Tech.com';
     $mailto = 'greg@eQuality-Tech.com';
Line 50: Line 50:
         echo "Try 'sudo tail /var/log/mail.log' to look for other possible errors.\n";
         echo "Try 'sudo tail /var/log/mail.log' to look for other possible errors.\n";
     }
     }
</source>
</syntaxhighlight>


If your application already has email capability, but it won't send, then turn on the mail_log feature in php.ini and check that sendmail/postfix is installed on your system.  You might start with <code>sudo apt-get install mailutils</code>.  If on AWS or datacenter, you can set up as an internet site and be done.  If you are behind a consumer broadband IP, you will probably need to setup a 'smarthosted' site and use (your own) IMAP credentials to send email through another provider.
If your application already has email capability, but it won't send, then turn on the mail_log feature in php.ini and check that sendmail/postfix is installed on your system.  You might start with <code>sudo apt-get install mailutils</code>.  If on AWS or datacenter, you can set up as an internet site and be done.  If you are behind a consumer broadband IP, you will probably need to setup a 'smarthosted' site and use (your own) IMAP credentials to send email through another provider.
Line 61: Line 61:
=== How do I use the 'mail' command? ===
=== How do I use the 'mail' command? ===
You're on a linux server and you see "You've got mail".  So, you type 'mail' and immediately have no idea how to process the messages.  See this excellent tutorial/write-up of the basic '''mail''' command: http://www.johnkerl.org/doc/mail-how-to.html  The <code>mail</code> command works like the editor '''<code>ed</code>''' which is to say not very well known today.  (See <code>man mail</code> -- The manual page was written in 1993.)  The man page refers to [https://docs.freebsd.org/44doc/usd/07.mail/paper.pdf The Mail Reference Manual] originally written by Kurt Shoens
You're on a linux server and you see "You've got mail".  So, you type 'mail' and immediately have no idea how to process the messages.  See this excellent tutorial/write-up of the basic '''mail''' command: http://www.johnkerl.org/doc/mail-how-to.html  The <code>mail</code> command works like the editor '''<code>ed</code>''' which is to say not very well known today.  (See <code>man mail</code> -- The manual page was written in 1993.)  The man page refers to [https://docs.freebsd.org/44doc/usd/07.mail/paper.pdf The Mail Reference Manual] originally written by Kurt Shoens
=== What is my mail server doing? ===
<code>mailq</code> tells you about what's in the queue (What it's going to send).
Grepping the mail log can tell you where your server has sent mail.
<syntaxhighlight lang="bash">
grep --perl-regex --only-matching ' to=[^ ,]*' /var/log/maillog | awk -F= '{print $2}' | sort | uniq -c
</syntaxhighlight>
<pre>
    37 admin@equality-tech.com\t
  305 meza-ansible
  305 <meza-ansible@my.qualitybox.us>
    35 root
</pre>


== Tools ==
== Tools ==
Line 69: Line 88:
https://support.google.com/a/answer/166852?hl=en
https://support.google.com/a/answer/166852?hl=en


If you've been running a server for a long time, and you have no idea how it works, you might find that there are a LOT of messages in root's mailbox.  Standard mailboxes are in /var/spool/mail/USER so <source lang="bash"> > /var/spool/mail/root</source> will truncate the mail file.
If you've been running a server for a long time, and you have no idea how it works, you might find that there are a LOT of messages in root's mailbox.  Standard mailboxes are in /var/spool/mail/USER so <syntaxhighlight lang="bash"> > /var/spool/mail/root</syntaxhighlight> will truncate the mail file.


{{References}}
{{References}}