Showing posts with label postfix. Show all posts
Showing posts with label postfix. Show all posts

Saturday, January 20, 2018

Setup mail forwarding in postfix on Debian or Ubuntu

Install Postfix
$ sudo apt-get install postfix
After Install check postfix status
$ sudo service postfix status

Further check that postfix is running a server on port 25 with the netstat command
$ sudo netstat -ltnp | grep 25
Output : 
tcp        0      0 127.0.0.1:25      0.0.0.0:*    LISTEN      1926/master     
tcp6       0      0 ::1:25            :::*         LISTEN      1926/master
Verify DNS settings of domain
$ sudo dig example.com mx

Configure postfix to forward mails

Check the path of config folder using  postconf command
$ postconf | grep config_directory
config_directory = /etc/postfix

Edit the main.cf file and add following lines at end if  it

virtual_alias_domains = mydomain.com anotherdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual

Now Create /etc/postfix/virtual file and add emails to forwad along with destination mails like:

myemail@domain.com   destination@gmail.com
othermail@domain.com otherdes@yahoo.com

First mail  address receive emails, and the second address would forward the emails.

For all forward emails use following lines

@mydomian.com  des@gmail.com 

After this save file and close it and run following commands

$ postmap /etc/postfix/virtual
$ sudo service postfix reload.

Now try to send an email from somewhere to the address on yourdomain and the same mail forwarded to other account.

Saturday, May 19, 2012

Filter mail with postfix header_checks


First up under /etc/postfix ensure that you have a file called header_checks. If not create it.
Next we want to ensure Postfix is configured to use this file so you do this from a command line by entering the following:
postconf -e "header_checks = regexp:/etc/postfix/header_checks"
The syntax in the header_checks file is:
/regex_pattern/ ACTION
Example :
#/etc/postfix/header_checks

/^From: "spam/ REJECT

/^To: example@example.com/ REDIRECT @esxe.com

/^Subject:.*viagra/ DISCARD
More Detail Link 1 Link 2