Saturday, April 22, 2017

How to send mails using php mail function on Ubuntu Linux server

Sending mails using php mail function on Ubuntu-Linux server
Sending mails using php mail function on Ubuntu-Linux server

Questions:
1. How to Send mails using php mail function on Ubuntu-Linux server?
2. How to use a Gmail account as a free SMTP server on your Ubuntu-Linux server?
3. How to send mails via Gmail SMTP server?
4. How to configure postfix to send mail to gmail?
5. Relaying Postfix mails via smtp.gmail.com?

Steps:
1. Install SMTP Server
2. Install Postfix
3. Install necessary packages
4. Configure Postfix
5. Create a new file for ssl password
6. Set the file permissions
7. Map file with postfix
8. Validate certificate
9. Reload postfix configuration
10. Send test mail
11. Set your gmail account as less secure

Step 1. Install SMTP sever
$sudo apt-get install ssmtp

Step 2. Install Postfix
$sudo apt-get install postfix

Step 3. Install required packages and ssl certificate
$sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules

Step 4. Configure the Postfix
$sudo nano /etc/postfix/main.cf

And add the following lines to it

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Step 5. Specify Gmail username and password in a file as ssl password
$sudo nano /etc/postfix/sasl_passwd

And add the following line to it

[smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD

Step 6. Set file permissions
$sudo chmod 777 /etc/postfix/sasl_passwd

Step 7. Update postfix config to use sasl_passwd file
$sudo postmap /etc/postfix/sasl_passwd

Step 8. Validate certificates
$cat /etc/ssl/certs/thawte_Primary_Root_CA.pem | sudo tee -a /etc/postfix/cacert.pem

Step 9. Reload postfix config for changes
$sudo /etc/init.d/postfix reload

Step 10. Send a test mail
$echo "Test mail from me." | mail -s "Test Mail" email_id@sample.com

Step 11. Set your Gmail account as less secure, logging into your gmail account using browser.

No comments:

Post a Comment

Sending mails using php mail function on Ubuntu Linux server

Sending mails using php mail function on Ubuntu Linux server