How to send email from loclahost Drupal hosted in Ubuntu?

Consider a situation in which you have installed Drupal in your Ubuntu machine. Now you would like to start sending email from localhost.If you have not setup Mail Transfer Agent(MTA) than you will not be able to send email from localhost.

What is Mail Transfer Agent(MTA)?

Wikipedia Says:
A mail transfer agent (MTA) or mail relay is software that transfers electronic mail messages from one computer to another using a client–server application architecture. An MTA implements both the client (sending) and server (receiving) portions of the Simple Mail Transfer Protocol.
To make it simple, MTA is the tool you require to transfer mail from localhost. There are many Mail Transfer Agents available in market. This tutorial will show you how to configure a mail transfer agent Postfix. Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail.

How do I install and configure Postfix in Ubuntu?

  • Check weather postfix is installed in your system. Type following in Terminal.

postfix --version

  • If you get this message than postfix is not installed.

The program 'postfix' is currently not installed. You can install it by typing:
apt-get install postfix

  • To install postfix type following command:

sudo apt-get install postfix

  • You will get configuration page after postfix gets installed. Select OK
  • After that select Internet Site. Select Ok.

  • Next part is very important. You will be asked to enter Mail Domain Name. I entered my laptop's name: sunil-laptop. This field will be auto-filled . Leave as it is.

  • Thats all with postfix configuration. Now restart your apache server.

sudo service apache2 restart

  • Now login to your drupal website as an administrator. Go to Site Configuration-> Site Information.
  • In Site Information, you will find a field called Email Address. Add email address in this format:

something@mail_domain_name

for my case:

updates@sunil-laptop

  • Thats it..It should send mail from localhost now.

Things to be considered:

  • This is tested in Ubuntu 12.04, Drupal 6
  • Make sure your internet service provider allows you to send mail.
  • Sometimes mail goes to SPAM. Dont forget to check spam folder.

Some Useful Commands:

  • Reconfigure postfix: sudo dpkg-reconfigure postfix
  • Remove Postfix completely: sudo apt-get purge postfix
  • Check mail log: gedit /var/log/mail.log

If you have any doubts and problems, please do comment. I will try to help you :)

Thanks for reading my first post :)

Technologies: 

Comments

Hi,

This works well with Drupal 7 and Drupal 8.

Alternatively one can easily send mail from localhost using a module called (SMTP Authentication). In this case there is no need to install postfix. You can use a third party SMTP Servers(like Yahoo mail, Gmail) for outgoing mails from your local Drupal website.

Link: http://drupal.org/project/smtp