This Sendmail&Gmail configuration is tested and works on Ubuntu 11.04 - 14.10.
# At first we must setup
sendmail and utilities.
sudo apt-get install sendmail sasl2-bin
# Sharutils are used to
send binary files as attachments.
sudo apt-get install sharutils
sudo /usr/sbin/sendmail -d0.1 -bv root
# In output find , SASLv2 and
STARTTLS. If they are present, all is ok.
# Now move to mail directory :
/etc/mail
cd /etc/mail
# Create file with name authinfo
sudo touch authinfo
sudo nano authinfo
Add folowing lines. Edit
them to match your e-mail and password.
AuthInfo:smtp.gmail.com "U:username"
"I:username@gmail.com" "P:password" "M:PLAIN"
AuthInfo:smtp.gmail.com:587 "U:username"
"I:username@gmail.com" "P:password" "M:PLAIN"
Save configuration by :
Ctrl+O , Ctrl+X
Execute command :
sudo makemap -r hash authinfo.db < authinfo
Now we have to make sasl.m4
file in /etc/mail/sasl/ directory.
For that, execute in
terminal :
make
When that’s done, we need to
add our configuration to sendmail.mc
file.
sudo nano sendmail.mc
Scroll to the end of file
and add these lines :
dnl #
include(`/etc/mail/m4/dialup.m4')dnl
include(`/etc/mail/m4/provider.m4')dnl
include(`/etc/mail/tls/starttls.m4')dnl
include(`/etc/mail/sasl/sasl.m4')dnl
FEATURE(`authinfo', `hash /etc/mail/authinfo.db')dnl
define(`SMART_HOST',`smtp.gmail.com')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
dnl #
dnl # Default Mailer setup
MAILER_DEFINITIONS
MAILER(`local')dnl
MAILER(`smtp')dnl
Save configuration file: Ctrl+O , Ctrl+X
Now we need to reconfigure
sendmail again.
To do that , execute in
terminal :
sudo make
/etc/init.d/sendmail reload
That’s all. Your mail relay
is ready for sending mail.
To send mail you can use
following commands :
- This will send a e-mail with message „This is Test” , subject will be „Subject about subject” to e-mail address username@gmail.com.
echo "This is Test" | sudo mail -s "Subject about subject"
username@gmail.com
- This will send a e-mail with message from text file mail_report.txt , subject will be „Daily Report” to e-mail address username@gmail.com.
mail -s "Daily Report" username@gmail.com < /home/janis/mail_report.txt
- This will send a e-mail with attached text file mail_report.txt , subject will be „Daily Report” to e-mail address username@gmail.com
For this we installed Sharutils earlier. Uuencode
is a part of this package
uuencode mail_report.txt mail_report.txt | mail -s "Daily Report"
username@gmail.com
0 comments :
Post a Comment
Comment: