Skip to content

Instantly share code, notes, and snippets.

@yourdesigncoza
Created April 19, 2013 14:44
Show Gist options
  • Save yourdesigncoza/5420802 to your computer and use it in GitHub Desktop.
Save yourdesigncoza/5420802 to your computer and use it in GitHub Desktop.
I ( Michael ) needed a basic mail transfer to perform basic SERVER mail functions ::: After searching it seems using sSMTP is the best bet ::: sSMTP a simple alternative to Sendmail ::: What is sSMTP ? It's an extremely simple MTA ( mail Transfer Application ), effective and simple way of getting mail off a system to your mail hub. NOTE ! it is …
# I ( Michael ) needed a basic mail transfer to perform basic server mail functions ::: After searching it seems using sSMTP is the best bet ::: sSMTP a simple alternative to Sendmail :::
# What is sSMTP ?
# It's an extremely simple MTA ( mail Transfer Application ), effective and simple way of getting mail off a system to your mail hub.
# NOTE ! it is all it does it does not receive mail, expand aliases or manage a queue.
# IMPORTANT : add your own data or parameters, I make use of double segments [[ your variable ]]. eg. ssh root@[[ 96.172.44.11 ]] should be replaced with ssh root@888.88.88.88 where "888.88.88.88" is your value, variable etc. I have a habit of using ":::" to indicate line ending and end of paragraph, crazy I know but be warned its just how I write ::: All notes are for my own use & should you use any it's at your own risk, it's NOT a Tutorial :::
# I'm new to server side setup so if I've erred or you know of a better way PLS. contribute :::
# mail me at support@yourdesign.co.za
# log into your server
ssh root@[[ server ipaddress ]]
#Update your server if you haven't done it recently :::
sudo apt-get update
sudo apt-get install ssmtp
# Configure sSMTP
sudo nano /etc/ssmtp/ssmtp.conf
#set your e-mail as root
root=[[ username@gmail.com ]]
# Mailhub ( Example below ~ for Gmail )
mailhub=[[ smtp.gmail.com:587 ]]
# Rewrite Domain
# Where will the mail seem to come from? ( eg. http://yourdomain.com || I use localhost as I have an unqualified domain ( 123.123.77 ) )
rewriteDomain=[[ localhost ]]
# The full hostname
hostname=[[ localhost ]]
# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes
# Authenticate User
AuthUser=[[ gmail-username ]]
# Authenticate Password
AuthPass=[[ gmail-password ]]
# 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 ( I'm using No, as I'll be receiving mail from monit )
FromLineOverride=YES
# Change the file permissions of /etc/ssmtp/ssmtp.conf because the password is printed in plain text (so that other users on your system cannot see your Gmail password).
chmod 640 /etc/ssmtp/ssmtp.conf
# Change the config file group to mail to avoid "/etc/ssmtp/ssmtp.conf not found" error.
chown root:mail /etc/ssmtp/ssmtp.conf
# Users who can send mail need to belong to "mail" group (must log out and log back in for changes to be used).
# You can edit this at a later stage if you need to remove a user with ( gpasswd -d [[ ubuntu-user ]] mail ) ( sudo nano /etc/group )
gpasswd -a [[ ubuntu-user ]] mail
# Adding reverse aliases
# A reverse alias changes the "From" address. Email will appear as if it's from a different email address. I personally haven't done this ( as I'm only receing system mail ) but if it's something you'd like to do then edit the revaliases file as follows:
sudo nano /etc/ssmtp/revaliases
# Paste this
# Just replace youruser with your Ubuntu username and username@gmail.com with your gmail address.
root:[[ username@gmail.com ]]:smtp.gmail.com:587
[[ youruser ]]:[[ username@gmail.com ]]:smtp.gmail.com:587
# Test your mail server
ssmtp [[ recipient_email@example.com ]]
TO: [[ recipient_email@example.com ]]
From: [[ your_mail@address.com ]]
Subject: Test Mail
Hello World !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment