Gentoo – SSMTP (Sending Mail)

image_pdfimage_print

Now that I finished showing you how to set up your LAMP server you are probably going to want to set up sendmail/ssmtp so that some of your new fancy websites can take advantage of it for their email services. Lets get started!

We are going to be using ssmtp which will replace sendmail as the MTA for the server. So as root type

emerge -av ssmtp

Once that completes we need to edit two config files.

Type

nano -w /etc/ssmtp/ssmtp.conf

and edit the following lines to reflect your email settings.

(Settings for a regular email account)

root=youremailaccount@somedomain.com
mailhub=smtp.domain.com
rewriteDomain=
hostname=smtp.domain.com
AuthUser=your_user_name
AuthPass=your_password
FromLineOverride=Yes

(Settings for a gmail account)

           
root=youraccount@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=smtp.gmail.com:587 
UseSTARTTLS=YES   
AuthUser=your_account 
AuthPass=your_password
FromLineOverride=Yes

Once you are done editing /etc/ssmtp/ssmtp.conf save the file and exit. Then type

nano -w /etc/ssmtp/revaliases

and press enter to edit the following lines.

(Settings for a regular email account)

root:youraccount@domain.com:smtp.domain.com
yournormaluser:youraccount@domain.com:smtp.domain.com

(Settings for a gmail account)

root:youraccount@gmail.com:smtp.gmail.com:587
yournormaluser:youraccount@gmail.com:smtp.gmail.com:587

When you are done save the file and exit. What this did was set up accounts for root and your main user to use to send emails from. Now we need to install mailx which will be used when sending emails from the server. So as root type

emerge -av mailx

Now we need to create a symlink from ssmtp to sendmail since sendmail has been replaced by ssmtp but some packages still like to use sendmail to send well mail! So as root do the following:

  • Type
    cd /usr/sbin
  • Type
    ln -s ssmtp sendmail

    to create the symlink, that’s it!

Now lets test the new mailer. As root do the following:

  • Type
    mailx test@domain.com

    (where test@domain.com is the email address you want to send to)

  • You should now see Subject: , type your subject and press enter.
  • You will now have a blank area, this is your email body, just start typing your email, when done press
    ctrl+D

    to send the email.

  • You will now see Cc: displayed, if you wish to copy the email to someone enter that address now otherwise just hit enter and the email will be sent.

Now you need to add you regular user to the ssmtp group by using the command:

gpasswd -a username ssmtp

Also note that if you want the ability to send emails through a website using php you will need to add the user apache to the ssmtp group by doing:

gpasswd -a apache ssmtp

Congratulations! Your server can now send mail, and you can also send emails directly from your terminal using mailx.

  1. No Comments