hint:
To enable sendmail to use STARTTLS, you need to:
1) Add this line to /etc/mail/sendmail.mc and optionally
to /etc/mail/submit.mc:
include(`/etc/mail/tls/starttls.m4')dnl
2) Run sendmailconfig
3) Restart sendmail
apt-get install phpmailer
/usr/sbin/ssmtp Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.< msg.txt
Install sSMTP and setup with Gmail on Ubuntu 16.04
This is a guide on how to install sSMTP and set it up with Gmail on Ubuntu 16.04.
I installed this to allow CSF/LFD to send email to me, as I didn’t want a full mail server.
Step 1:
Login to SSH as root.
Step 2:
Makre sure your Ubuntu Repository, is up to date.
sudo apt-get update
Step 3:
Install sSMTP
sudo apt-get install ssmtp
Step 4:
Configure sSMTP
nano /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
AuthUser=Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.
AuthPass=MyPassword
UseTLS=YES
UseSTARTTLS=YES
# Where will the mail seem to come from?
rewriteDomain=gmail.com
# The full hostname
hostname=localhost
# Are users allowed to set their own From: address?
# YES – Allow the user to specify their own From: address
# NO – Use the system generated From: address
FromLineOverride=YES
Step 5:
Add reverse aliases
nano /etc/ssmtp/revaliases
Add the line:
root:Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.:smtp.gmail.com:587
Step 6:
Create a test messae to send
cd /root
nano msg.txt
Add the following lines:
To: Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.
From: Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.
Subject: test email
Hello World!
Step 7:
Test to make sure it all working
cd /root
/usr/sbin/ssmtp Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε. < msg.txt
Info:
Be sure to set your Gmail email address where it has:
Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.
Remember to set your Password in the ssmtp.conf file.
If you are using Two-Factor you will need to create an App password, instead.
************** for noisyjohn ***********************
mailhub=smtp.gmail.com:587
AuthUser=Αυτή η διεύθυνση ηλεκτρονικού ταχυδρομείου προστατεύεται από τους αυτοματισμούς αποστολέων ανεπιθύμητων μηνυμάτων. Χρειάζεται να ενεργοποιήσετε τη JavaScript για να μπορέσετε να τη δείτε.
AuthPass=CityOfCHaoS1951
UseTLS=YES
UseSTARTTLS=YES
# Where will the mail seem to come from?
#rewriteDomain=
rewriteDomain=gmail.com
# The full hostname
hostname=localhost
FromLineOverride=YES
*************************************************************
how to fix “send-mail: Authorization failed 534 5.7.14 ”
It may take more than one step to fix this issue
Take the step mentioned earlier. Log into your google email account and then go to this link: https://www.google.com/settings/security/lesssecureapps and set "Access for less secure apps" to ON. Test to see if your issue is resolved. If it isn't resolved, as it wasn't for me, continue to Step #2.
Go to https://support.google.com/accounts/answer/6009563 (Titled: "Password incorrect error"). This page says "There are several reasons why you might see a “Password incorrect” error (aka 534-5.7.14) when signing in to Google using third-party apps. In some cases even if you type your password correctly." This page gives 4 suggestions of things to try.
postfix would be an overkill if you just need to send emails from php while developing applications on your home computer.
Use a very simple and lightweight package ssmtp. It will use any smtp server to send outbound emails. Install it by running:
sudo apt-get install ssmtp
Then edit /etc/ssmtp/ssmtp.conf file, comment out existing mailhub line and add the following lines (this example is for gmail smtp server):
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=@gmail.com
AuthPass=
smtp-auth.forthnet.gr
(Provide your gmail username & password. Of course you can use any other SMTP server).
Now make sure that your php.ini has correct sendmail_path. It should read as:
sendmail_path = /usr/sbin/sendmail -t