banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Tip Top Tips: Send Email From The Command Line With Sendmail Using A Gmail Account


Editor's Note: Tip Top Tips is a monthly column in The PCLinuxOS Magazine. Each month, we will feature -- and possibly even expand upon -- one tip from the PCLinuxOS forum. The magazine will not accept independent tip submissions specifically intended for inclusion in the Tip Top Tips column. Rather, if you have a tip, share it in the PCLinuxOS forum's "Tips & Tricks" section. Your tip just may be selected for publication in The PCLinuxOS Magazine.

This month's tip comes from PCLinuxOS forum member MBantz.

I have just completed a project where I needed PCLinuxOS to send emails from a php web form using sendmail. It took me some time to figure out, and perhaps this can be useful. It can also be used to send emails directly from the command line or from scripts.

1) Install sendmail and sendmail-cf from Synaptic

2) Create a Gmail account, log on to this account and allow less secure login (in the Gmail account settings)

3) As root - do the following:

mkdir -m 700 /etc/mail/authinfo/
cd /etc/mail/authinfo


Create a text password file and name it /etc/mail/authinfo/gmail-auth with this content (replace e-mail address and password -after- the colons):

AuthInfo: "U:root" "I:gmailusername" "P:gmailpassword"

Then, create sendmail database map:

makemap hash gmail-auth < gmail-auth



Put these lines in your /etc/mail/sendmail.mc configuration - just above the first MAILER definition line:

define(`SMART_HOST',`[smtp.gmail.com]')dnl

define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl

define(`confAUTH_OPTIONS', `A p')dnl

TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl


Then, refresh sendmail config:

make -C /etc/mail

4) Configure automatic start of sendmail:

Still as root:

Edit the file

/etc/sysconfig/sendmail

and add this line:

DAEMON="yes"

Then, start sendmail service:

service sendmail start

Test with:

echo "Just testing my sendmail gmail relay" | mail -s "Sendmail gmail Relay" my-email@my-domain.com

Cheers!

Editor's note: Google will limit individual users to 500 emails per 24 hour period using a third party agent, such as sendmail. Users needing to send more than 500 emails per 24 hour period should look into a business account with Google, or a different email provider.



Previous Page              Top              Next Page