Mailx: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 23: Line 23:
</pre>
</pre>


==Configuring mailx to Use a Google SMTP Server==
==Configuring mailx to Relay via a Google SMTP Server==
 
===Create a Dedicated User===
 
This step is optional, but it is a good idea to use a separate "service" account to send service e-mails. The remaining of the example uses a "service@novaordis.com"
 
<blockquote style="background-color: Gold; border: solid thin Goldenrod;">
:<br>'''Important''' If the service account was specifically created for this job, you will need to log in at least one time via the web interface (to accept terms and conditions and possibly to change the password), otherwise you will get an error and ''"Please log in via your web browser and then try again."''<br><br>
</blockquote>
 
===SMTP Relay Service===
 
* Google documentation: SMTP relay service setting https://support.google.com/a/answer/2956491?hl=en
 
The relay server that requires TLS encryption is smtp-relay.gmail.com:587.
 
===Individual Application SMTP Settings===
 
* Google documentation: Google Apps SMTP settings to send mail from a printer, scanner, or app: https://support.google.com/a/answer/176600?hl=en
 
 
<font color=red>'''TODO''' unfinished, not working.</font>
 
First, you will need to make sure <tt>mailx</tt> has access to a valid Google certificate in an NSS certificate database. Firefox usually has it in its profile directory, but it is a good idea to initialize a private certificate database for <tt>mailx</tt>.
 
This page explains how to do that:
 
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
:[[NSS#Create_a_New_Certificate_Database_and_Import_Google.27s_Certificate|Create a New NSS Certificate Database and Import Google's Certificate]]
</blockquote>
 
This page explains how to "re-use" Firefox Mozilla certificate database:


<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
:[[Firefox#Re-Use_Firefox.27s_NSS_Certificate_Database|Re-Use the Firefox NSS Certificate Database]]
:[[Configure mailx to Relay via a Google SMTP Server]]
</blockquote>
</blockquote>


Assuming you provision <tt>root</tt> GMail SMTP access, move the <tt>certs</tt> directory created at the previous step under <tt>~root</tt> as follows:
=Using from Command Line=


<pre>
<pre>
mv .../certs ~root/.certs
echo "test" | mailx -A gmail -s "test" test@example.com
</pre>
</pre>
Configure <tt>/etc/mail.rc</tt> as follows:
<pre>
...
account gmail {
set smtp-use-starttls
set smtp-auth=login
set smtp=smtps://smtp.gmail.com:587
set from="root@now510"
set smtp-auth-user=your.smtp.user@gmail.com
set smtp-auth-password=your.pass
set ssl-verify=ignore
set nss-config-dir=/root/.certs
}
</pre>
<font color=red>TODO: try a per-user mail.rc that is read restricted because it contains sensitive credentials.</font>
Test:
<pre>
echo "mailx e-mail" | mailx -v -A gmail -s "test" somebody@example.com
</pre>
Deplete:
* http://www.systutorials.com/1411/sending-email-from-mailx-command-in-linux-using-gmails-smtp/
* http://stackoverflow.com/questions/16799407/mailx-and-gmail-nss-config-dir
* http://serverfault.com/questions/498588/smtp-gmail-com-from-bash-gives-error-in-certificate-peers-certificate-issuer
* http://www.systutorials.com/1411/sending-email-from-mailx-command-in-linux-using-gmails-smtp/
* http://serverfault.com/questions/498588/smtp-gmail-com-from-bash-gives-error-in-certificate-peers-certificate-issuer
Next:
* Clarify mail on now510: be able to send mail and test how does cron reacts to it (success or failure). Document -> [http://www.systutorials.com/1411/sending-email-from-mailx-command-in-linux-using-gmails-smtp/], understand the nss business.

Latest revision as of 07:41, 17 March 2016

Internal

Installation

yum install mailx

Configuration

Verbose and Debug Output

In order to get verbose output, use the -v on mailx command line. This will send verbose output to stdout as the e-mail is being sent.

The debug option dumps the protocol headers, but it configures mailx to not send anything externally - no connection is attempted:

...
set debug
...

Configuring mailx to Relay via a Google SMTP Server

Configure mailx to Relay via a Google SMTP Server

Using from Command Line

echo "test" | mailx -A gmail -s "test" test@example.com