Cloud Server Tutorial: Sending outgoing emails for your contact form

ORANGE COUNTY, Calif. -- This tutorial assumes that you have a server hosted in the Cloud and runing Ubuntu Hardy distro with Apache. This turorial also assumes that you do not need your server to receive emails. If you need to have your website's contact form send out an email and you are hosted in the cloud you need to install Postfix on your server. and make some configuration changes to your server to play nice with ISP's mail servers. 

After you login to your server via SSH, the first thing to look at is the Cloud Server hostname.

This is simply the 'name' of the Cloud Server and is used in the headers of the email (the headers can be thought of as the address and sender label on the email).

Setting the hostname via the command line involves the very simple adjustment of a couple of files.

We can start by checking what the current hostname is:

hostname -f

On my Cloud Server, the output is:

cloudserver1

For these basic articles I am going to use the domain 'mail.democloud.com' - I am setting up a mail server so that makes sense.

I need to change the hostname to match the domain:

sudo nano /etc/hostname

Replace the current hostname (cloudserver1) with the one you need (in this case mail.democloud.com).

The second file to edit is:

sudo nano /etc/hosts

The default looks like this on my Cloudserver:

127.0.0.1       localhost localhost.localdomain  
127.0.0.1 cloudserver1

Following on from what we are doing, replace 'cloudserver1' with 'mail.democloud.com'.

Of course, replace mail.democloud.com with your domain.

Conduct a quick reboot:

sudo shutdown -r now

and check the hostname:

hostname -f

The output is now:

mail.democloud.com

Good start!

Now, we need to properly set the reverse DNS for the server.

Navigate to your Server's DNS tab and scroll down to the Reverse DNS section. Change the relevant field to the domain name which you'd like in the rDNS record

The RDNS may take a while to propagate and you really need to wait until it has done so before you can fully configure and test any mail setup.

To check the RDNS, you need to input the IP address if the Cloud Server into the 'dig' command.

Note that 'dig' is not installed on a base Ubuntu Hardy Cloud Server:

sudo aptitude install dnsutils

So, to check the RDNS:

dig -x 208.75.84.20

In this case, the output includes the correct answer:

dig -x 208.75.84.20  
...
...
;; QUESTION SECTION:
;20.84.75.208.in-addr.arpa. IN PTR
;; ANSWER SECTION: 20.84.75.208.in-addr.arpa. 3477 IN PTR mail.democloud.com.

Now that we have configured the server, install Postfix and configure it.

Use this command to install Postfix

sudo aptitude install postfix

**If you need to trouble shoot your Postfix, uninstall Postfix, or make sure you set Postfix up correctly, use this command to reconfigure it. You may not want to uninstall, since you can reconfigure.

sudo dpkg-reconfigure postfix

Insert the following details when asked (replacing mail.democloud.com with your domain name if you have one):

  • General type of mail configuration: Internet Site
  • System mail name: mail.democloud.com
  • Root and postmaster mail recipient: [your_admin_username]
  • Other destinations for mail: [make it blank]
  • Force synchronous updates on mail queue?: No
  • Local networks: [leave as default]
  • Mialbox size limit (bytes): 0
  • Local address extension character: +
  • Internet protocols to use: all

Let's conduct a quick test to see if postfix is actually sending mail.

You will need to send an email to a working email address using the 'mail' command:

mail address@example.com

Replace the email address with one of your choosing (remember this must be a working email address).

The output asks for the subject of the email. Once done, press enter/return.

Next enter the subject of the email. Once done, press enter/return and then a single period (.) - the period lets mail know the body is finished.

Finally press enter/return again to send the email (you may need to do this twice so you skip the 'CC:' entry.

The output on my machine looks something like this:

mail address@example.com  
Subject: test email from democloud.com
test body of the email.
.
Cc:

No confirmation is given that the email has been sent (the logs will show the details) but check the receiving email address and voila! a nice, fresh email with the subject 'test email from democloud.com'.

Add a Comment