Home / Articles / BSD / FreeBSD / Using Gmail SMTP to send email in FreeBSD

Using Gmail SMTP to send email in FreeBSD

Using Gmail SMTP to send email in FreeBSD
 
Using Gmail SMTP to send email in FreeBSD
  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 5/5 (3 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


The simplest way of sending emails by using another SMTP is the using of sSMTP program. The sSMTP program delivers emails from local computer to a configured mailhost. sSMTP is not a mail server. And it can be used for servers which don't have a static IP. For this program two things need:

  • internet connection
  • registered email account on any email service ( for example Gmail )

This article shows how configure sSMTP for Gmail account in few steps.

Note: all steps can be done only if you are logged in like root.


Disable default sendmail

It can be done by adding the following lines to file /etc/rc.conf:

sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

After this you need to reboot, but If for some reason you can do it then you can kill sendmail:

killall sendmail

Install sSMTP

cd /usr/ports/mail/ssmtp/ && make install

Configure the sSMTP

The next thing is what you need to create a configuration file for ssmtp here /usr/local/etc/ssmtp/ssmtp.conf and add the following:

root=<your_email>
mailhub=smtp.gmail.com:587
AuthUser=<your_email>
AuthPass=<your_password>
UseSTARTTLS=YES

Where:
<your_email> - is a real email on Gmail for example test@gmail.com.
<your_password> - is a password for email account test@gmail.com.

Test sSMTP

Create a txt file "youtestmessage.txt" with the following text:

To: yourmail@gmail.com
From: yourmail@gmail.com
Subject: Testmessage
This is a test for sending

Where yourmail@gmail.com is your current or second email to get test email and make sure that ssmtp sends the email. And run command:

ssmtp -v yourmail@gmail.com < youtestmessage.txt

After this you will get an output information about sending email. If there is no errors then you can check out your post on yourmail@gmail.com and make sure that email has been delivered successfully.

But, if you get errors and don't get email then check ssmpt config and Gmail account which you use for sending post.

Replace sendmail with sSMTP

It makes ssmtp the default mailer for system.

mv /usr/sbin/sendmail /usr/sbin/sendmail.org
ln -s /usr/local/sbin/ssmtp /usr/sbin/sendmail

Make sure that mail is working

mail -v -s "test subject" yourmail@gmail.com

The using of Gmail SMTP is a good thing because Gmail is very fast and large e-post service. But, there is one specific thing that Gmail always replaces a sender name by Gmail account name which you use for sending emails. And there is no way to prevent this.

sSMTP is the fastest solution for sending emails but is not the best one. For example if you have a site with page or application which send emails, the time of loading pages will be very long. For example if a time for loading your page was few miliseconds when you use sSMTP it will be increased to few second. It happens because, application will wait until sSMTP completes the sending of email. So, sSMTP can't add email in queuea and send them in background.
If you want to prevent this then you will probably need to use the Postfix which also can be used for sending emails by Gmail or another e-post service.


 

Read also

Install Apache in FreeBSD

Install Apache in FreeBSD

Log in or create a user account to post a comment.

easyos.net
117217982212577402640

Quick navigation

General navigation