This shows you how to send mails from a - in this case virtual debian server inside VirtualBox - server to an external SMTP server. You can use your own server, Gmail or any other SMTP server you have access to.
This can then be used to send mail from PHP, Rails, Python, console or whatever you like.
The steps are for a debian wheezy server.
You will need:
- a username and password for the smtp server
- the address and port of the smtp server
- a (virtual) server
sudo apt-get install ssmtp
Open the config file and make it look like the following. Change all uppercase strings (except the YES and NOs) to the your personal login, server, etc. I did not replace the port, as it should be the standard of 587.
sudo nano /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=YOUR_EMAIL_ADDRESS_HERE
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=YOUR_SMTP_SERVER_HERE:587
# Where will the mail seem to come from?
# Set it to something like yourdomainname.com
rewriteDomain=YOUR_DOMAIN_NAME_HERE
# The full hostname
hostname=YOUR_EMAIL_ADDRESS
# Do not replace the YES ;)
UseSTARTTLS=YES
AuthUser=YOUR_USERNAME_FOR_THE_SMTP_SERVER
AuthPass=YOUR_PASSWORD_FOR_THE_SMTP_SERVER
# 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
FromLineOverride=YES
Save the file with ctrl+x
You can configure forwarding of mails in the following file. You don't need to if you don't want/need forwarding.
sudo nano /etc/ssmtp/revaliases
# sSMTP aliases
#
# Format: local_account:outgoing_address:mailhub
#
# Example: root:[email protected]:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
root:YOUR_EMAIL_ADDRESS:YOUR_SMTP_SERVER_HERE:587
Save it with ctrl+x
You can test it with the following command on the commandline:
sudo ssmtp YOUR_EMAIL_HERE
Type some words, add a new line and close with (double) crtl+d
to send the message.