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 :
- Check weather postfix is install in your system. Type following in Terminal.
- 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
- if it is installed, you can reconfigure postfix:
sudo dpkg-reconfigure postfix
- Select “Internet with smarthost”. I’m using this setting as I’m going to send mail through my Exchange mail server.
- Type Domain name. Since our user will be named “Rancid” and the mail domain will be “domain.local”, we will type in:
- Enther the FQDN or IP of the smarthost, you can also define a custom port like port 26, like this host:port
- Our Exchange FQDN is:
- 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
- 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: email@example.com 250 2.1.0 Ok rcpt to: firstname.lastname@example.org 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:~$
- 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
- You must check also log mail files under : /var/log/mail.* : All mail server message log files (Ubuntu use postfix mail sending by default).
- Our Exchange FQDN is:
Command Line for mail:
The main command to check if you have mail is mail. Run the command below, replacing “email@example.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" firstname.lastname@example.org
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" email@example.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" firstname.lastname@example.org -c email@example.com -b firstname.lastname@example.org
It is also possible to specify multiple recipients by joining them with a comma.
$ mail -s "Hello World" email@example.com,firstname.lastname@example.org
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