SMTP stands for Simple Mail Transfer Protocol, lets you send email messages through your email account using your existing email service. This email service is subject to your interest. It could be any like: Gmail Relay, Snail Mail etc.
In this post we are going to configure Gmail Relay to send emails.
Install Postfix and other required packages.
yum install postfix
yum install mail*
yum install libsasl2-modules*
yum install cyrus-sasl-lib.x86_64 cyrus-sasl-lib.i686 -y
yum install cyrus-sasl-plain -y
In this post we are going to configure Gmail Relay to send emails.
Install Postfix and other required packages.
yum install postfix
yum install mail*
yum install libsasl2-modules*
yum install cyrus-sasl-lib.x86_64 cyrus-sasl-lib.i686 -y
yum install cyrus-sasl-plain -y
- Configure Postfix main configuration
- Open main configuration file in edit mode.
vi /etc/postfix/main.cf - Add these lines in main configuration file at the bottom:
smtp_sasl_security_options = relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd smtp_sasl_authentication_filter =
- Save and exit
- Open main configuration file in edit mode.
- Create /etc/postfix/sasl/passwd
- Create a directory sasl under /etc/postfix and create a file passwd with contents below:
[smtp.gmail.com]:587 username@gmail.com:password
Save and exit - Change permission
chmod 600 /etc/postfix/sasl/passwd - Create lookup table via postmap
postmap /etc/postfix/sasl/passwd
Issuing that command will create passwd.db
- Create a directory sasl under /etc/postfix and create a file passwd with contents below:
- Generate your own CA certificate
- Change directory to /etc/pki/tls/certs
cd /etc/pki/tls/certs - Create a key and test certificate in one file
make hostname.pem
You will something like[root@ip-10-112-95-49]# make hostname.pem umask 77 ; \ PEM1='/bin/mktemp /tmp/openssl.XXXXXX' ; \ PEM2='/bin/mktemp /tmp/openssl.XXXXXX' ; \ /usr/bin/openssl req -utf8 -newkey rsa:1024 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \ cat $PEM1 > hostname.pem ; \ echo "" >> hostname.pem ; \ cat $PEM2 >> hostname.pem ; \ rm -f $PEM1 $PEM2 Generating a 1024 bit RSA private key ……………………….++++++ …..++++++ writing new private key to ‘/tmp/openssl.z12084' —– You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter ‘.’, the field will be left blank. —– Country Name (2 letter code) [GB]: State or Province Name (full name) [Berkshire]: Locality Name (eg, city) [Newbury]: Organization Name (eg, company) [My Company Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) []: Email Address []:
- Fill-up the necessary information and copy the file on /etc/postfix as cacert.pem
cp /etc/pki/tls/certs/hostname.pem /etc/postfix/cacert.pem
- Change directory to /etc/pki/tls/certs
- Restart the postfix service
service postfix restart
- Inspect now your postfix logs to see if it can send out mails now to gmail servers
A successful message states something like [[BR]] May 3 17:35:00 FLT postfix/smtp[28244]: 0ABB61CE32A: to=
, relay=smtp.gmail.com[74.125.93.109]:587, delay=5, delays=0.41/0.02/2.7/1.8, dsn=2.0.0, status=sent (250 2.0.0 OK 1272879300 8sm8902550qwj.38)
Check Email functionality
To check that emails are working fine, use mail command.
mail -s subject recpientemailaddress
Example: mail -s "Email Notification" gaurav81083@gmail.com
.
mail -s subject recpientemailaddress
Example: mail -s "Email Notification" gaurav81083@gmail.com
.
Checking mail log
To check the mail logs, use tail command
tail -f /var/log/maillog
tail -f /var/log/maillog
No comments:
Post a Comment