Send mail in Ubuntu server with Gmail SMTP

In a web project, email function is quite important thing.  For sending email you can use a free SMTP server or sendmail function in your server. So how to send mail in Ubuntu server? The answer is Postfix or SSMTP.  But SSMTP is simper way. Because all we have a free smtp server (e.g Gmail SMTP), and also SSMTP is easier to install.

A wise man never knows all, only fools know everything

A wise man never knows all, only fools know everything

Now, you install SSMTP packet:

And open the config file:

Add new content as below (do not forget change your_emal and your_gmail_password, your_gmail_username):

(It seems that Gmail is more secure, so you have to enable less secure to use SMTP Gmail

To test, you need install send mail client:

Finally, do a test:

You are a PHP developer, the server now can run mail php function. However, you are using Swiftmailer Library, you will got a error message as below:

Because Swiftmailer always try to telnet to localhost to check mail server before sending mail. But SSMTP does not support telnet.

So It is time to use Postfix, I will have a article to so you some tips to install it.