I have found the way to send e-mails via Gmail. It can be done with mail() function in a console:
php -r "mail('[email protected]', 'Subject', 'Body');"
If to call mail() via php file, e-mails won’t be sent and it means that Magento won’t send anything.
Installing and Setting up Sendmail
- Check if it wasn’t installed before with the command ls -la `which sendmail`
- If not, use the command sudo apt-get install sendmail
- When the installing is finished run the command sudo sendmailconfig
- Open etc/hosts:
127.0.0.1 localhost.loc Name 127.0.1.1 Name
(get the name from here)
- Specify the local hosts’ names, Sendmail will receive requests of e-mail sending from these names. Point them in the file /etc/mail/local-host-names:
localhost.loc Name
- Then you have to add several lines to the file /etc/mail/sendmail.mc to send e-mails via Gmail. Add the lines above MAILER parameters, otherwise, you’ll get an error in configuration.
define(`SMART_HOST',`smtp.gmail.com')dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl define(`RELAY_MAILER',`esmtp')dnl define(`RELAY_MAILER_ARGS', `TPC $h 587')dnl FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
- Create the folder /etc/mail/auth. Add the file client-info to it, this file will store the login and the password for [email protected].
# mkdir /etc/mail/auth # touch /etc/mail/client-info
- Add to the file client-info your authorization parameters (change my.name to your login as well as password):
AuthInfo:smtp.gmail.com "U:root" "I:my.name" "P:password" "M:PLAIN" AuthInfo:smtp.gmail.com:587 "U:root" "I:my.name" "P:password" "M:PLAIN"
- Make this file/folder accessible only for a root user for security purposes:
# chmod 600 /etc/mail/auth/client-info # chmod 700 /etc/mail/auth
- Transform the file into the needed format:
# makemap -r hash /etc/mail/auth/client-info.db < /etc/mail/auth/client-info
- Do the assembling of configuration files for Sendmail:
# cd /etc/mail # make
- Restart MTA (mail transfer agent) and your server to apply changes:
sudo /etc/init.d/sendmail restart (/etc/init.d/sendmail reload) sudo /etc/init.d/apache2 restart
Testing e-mail sending
Use the terminal for testing:
telnet localhost smtp
We should get:
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
220 localhost.loc ESMTP Sendmail 8.14.4/8.14.4/Debian-4.1ubuntu1; Sat, 26 Jul 2014 21:46:56 +0300; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
Start the testing by inserting hello localhost.
Response 250 localhost.loc Hello localhost [127.0.0.1], pleased to meet you.
Then the commands and responses alternate:
mail from: [email protected]
250 2.1.0 [email protected]… Sender ok
rcpt to: [email protected]
250 2.1.5 [email protected]… Recipient ok
data
354 Enter mail, end with “.” on a line by itself
Insert the text of a test e-mail, be sure to end it with a point:
test message
.
Press Enter and get the response:
250 2.0.0 s6QItc6L010145 Message accepted for delivery
Now, you have to setup the mail client to get [email protected] sent/received e-mails from the website.
Set up Thunderbird first. Open Create > Others accounts. Choose Unix Mailspool (Movemail) account’s type, press Next. Enter a name and specify e-mail [email protected]. Then press Next till the step Done. If everything is done properly, you’ll see the test letter in the inbox.
Sending via php mail()
Open /etc/php/5.6/apache2/php.ini
Remove commenting sendmail_path and add = /usr/sbin/sendmail -t -i to it.
Then check apachectl -t. If everything is ok, do a restart.
You can run the test via the terminal:
php -r "mail('[email protected]', 'Subject', 'Body');"