Ubuntu Postfix and Drupal configure Mail smarthost with Exchange.

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. To make it simple, MTA is the tool you require to transfer mail from localhost.

Installing Postfix :

  1. Check weather postfix is install in your system. Type following in Terminal.
    postfix --version
  2. 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
  3. if it is installed, you can reconfigure postfix:
    sudo dpkg-reconfigure postfix
  4. Select “Internet with smarthost”. I’m using this setting as I’m going to send mail through my Exchange mail server. ubuntu-drupal
  5.  Type Domain name. Since our user will be named “Rancid” and the mail domain will be “domain.local”, we will type in:
     domain.local

     

  6. Enther the FQDN or IP of the smarthost, you can also define a custom port like port 26, like this host:port
    1. Our Exchange FQDN is:
       EXCH2010.domain.local
    2. That’s it. We have set up anonymous no-authentication mailrelay up. Now we have to setup the Exchange-server to accept these relays.
      Thats all with postfix configuration. Now restart your apache server.

      sudo service apache2 restart
    3. Time to test if it Works (ping server and telnet on port 25) :
      myserver@myserver:~$ telnet localhost 25
       Trying 127.0.0.1...
       Connected to localhost.
       Escape character is '^]'.
       220 myserver ESMTP Postfix (Ubuntu)
       helo myserver.domain.local
       250 myserver
       mail from: myserver@domain.local
       250 2.1.0 Ok
       rcpt to: receiver@domain.local
       250 2.1.5 Ok
       data
       354 End data with .
       Hi,
       This is test mail. Sent from Postfix linux server.
       smart host relay configuration.
       Thanks!!!
       .
       250 2.0.0 Ok: queued as xxxxxxxx
       quit
       221 2.0.0 Bye
       Connection closed by foreign host.
       myserver@myserver:~$
    4. If you are having issues with mail not popping up in your mailbox, you should review the settings using:
       sudo nano /etc/postfix/main.cf
    5. You must check also log mail files under : /var/log/mail.* : All mail server message log files (Ubuntu use postfix mail sending by default).

Command Line for mail:

The main command to check if you have mail is mail. Run the command below, replacing “user@yourmaildomain.com” with your e-mail address. The s option specifies the subject of the mail followed by the recipient email address.

$ mail -s "Hello World" user@yourmaildomain.com

Now you have to type in your message. When you’re done, hit ‘control-D’ at the beginning of a line

# mail -s "This is the subject" m00n.silv3r@gmail.com
Cc: 
Hi Silver
How are you doing
Hope its going fine.
Bye

Now, the first mail is sent on command line. The content of the mail can be taken from a file as follows:

In some distributions, the shell asks other fields interactively like ‘Cc’ (Carbon copy) first. Just hit enter here to skip. Next type in your message. When you enter the mail address or addresses with commas, you need to press enter to go to the new line for message body.

 

Other useful parameters in the mail command are :

-s subject (The subject of the mail)
-c email-address (CC – send a carbon copy to email-address)
-b email-address (BCC – send a blind carbon copy to email-address)

Here’s and example of how you might use these options

$ mail -s "Hello World" user@yourmaildomain.com -c usertocc@yourmaildomain.com -b usertobcc@yourmaildomain.com

It is also possible to specify multiple recipients by joining them with a comma.

$ mail -s "Hello World" user1@yourmaildomain.com,user2@yourmaildomain.com

Some Useful Commands for postfix :

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

extradrmtech

Since 20 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions. I am an experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. When not writing code, I like to dance salsa and swing and have fun with my little family.

You may also like...