Postfix - adding domain + forwarding setting - redirect

I have a question as to postfix add a new domain to be able to it to send and receive e-mails?
How to redirect all emails sent to this domain went to an external email address?
Regards,
Darek

Adding a domain will be adding it to mydestination= example.com in main.cf
the second question is called a "catch all"
Mapping is done using /etc/postfix/virtual file.
vim /etc/postfix/virtual
Append code as follows, replacing domain and emailusername with actual values:
#yourdomain.com emailusername
Save and close the file. Run following command:
postmap /etc/postfix/virtual
Also make sure you have following line in /etc/postfix/main.cf file:
virtual_alias_maps = hash:/etc/postfix/virtual
If you just added above, line reload postfix:
service postfix reload

Related

Why is my custom postfix virtual mailbox not workng

What I've got
I'm testing postfix on Virtualbox. Initially I had success by passing incoming mail (towards my domain) to a pipe (approach 1 from this answer https://superuser.com/a/1490699 ) and letting outgoing mail send as normal.
Now I've switched my postfix config to use virtual mailbox features (still on Virtualbox) so I can use Mysql to query that the domain and user exists before accepting mail. With config such as:
virtual_transport = myhook:dummy
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
all working well when testing via postmap -q, and I removed my domain from "mydestination" to ensure mail is not transported to local.
The Issue
I've followed a lot of guides
https://www.linode.com/docs/guides/email-with-postfix-dovecot-and-mysql/
https://wiki.gentoo.org/wiki/Complete_Virtual_Mail_Server/Postfix_to_Database
However these guide are made with Dovecot in mind and I wont be using that.
When sending mail via command line to another user that is found within the virtual mailboxes I get the following error
to=<me#laravel8.test>, orig_to=<me>, relay=none, delay=36, delays=36/0.02/0.05/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=laravel8.test type=AAAA: Host not found)
This is despite the domain appearing in virtual_mailbox_domains. Changing to ipv4 had no change
I read that this can be due to Postfix not using /etc/hosts (which points laravel8.test to 127.0.0.1) so I added the following lines to main.cf
lmtp_host_lookup = native
smtp_host_lookup = native
But now I get this error:
to=<support#laravel8.test>, relay=none, delay=0, delays=0/0/0/0, dsn=5.4.6, status=bounced (mail for laravel8.test loops back to myself)
Yes, Is that not what I want? I want mail sent to another user to then transport this mail to my pipe as declared in virtual_transport.
No matter what I do I only seem to encounter more issues.
Please help if possible.
Issue seems to be
/etc/postfix/mysql-virtual-mailbox-domains.cf
was
user = root
password =
hosts = 127.0.0.1
dbname = laravel
query = SELECT domain FROM mailbox WHERE domain='%d' LIMIT 1
When it should be
user = root
password =
hosts = 127.0.0.1
dbname = laravel
query = SELECT domain FROM mailbox WHERE domain='%s' LIMIT 1
I got really confused about when and where %s should be used or %d and %u. Here postfix only sends domain to this mysql query so must be whole string as %s

Setting up DKIM for Parse.com

How can I set up DKIM with the DNS record for the domain we use for mails being sent from Parse.com, like registration emails?
Parse has only this one line of instructions:
"Run the following in your terminal: dig +short k1._domainkey.parse.com txt for the most up-to-date DKIM value."
But what next? The output is something like this: "k=rsa\; p=MIGfMA0GCSqGSIb3...44Dyfnzp7zmQIDAQAB".
How does the DNS entry has to look like?
Like this?
k1._domainkey.parse.com IN TXT "k=rsa\; p=MIGfMA0GCSqGSIb3...44Dyfnzp7zmQIDAQAB"
You need to put this on your own DNS. If your domain is company.com, a record like this in your company.com zone file should do it:
k1._domainkey.company.com In TXT "k=rsa\; p=MIGfMA0GCSqGSIb3...44Dyfnzp7zmQIDAQAB"
Just make sure that parse.com will DKIM sign the message with your company.com domain and set d=k1!
According to http://dkimcore.org/c/keycheck, I needed to delete the \ after k=rsa for the key type to be valid.

Configuring postfix to only send to a specified domain

In order to not accidentally send real emails to people outside the company from an integration test server, I'd like to configure postfix to only send emails to addresses like *#somecompany.com and drop all other emails. Is it possible to somehow configure it in /etc/postfix/main.cf and if yes then how?
You can specify like that with the help of /etc/postfix/transport file
You can add the line transport_maps = hash:/etc/postfix/transport in main.cf
Do the steps below
Create a transport - transport1 and Mail sent to user "user#gmail.com" should go through transport1 and all other mail sent should go through default.
First stop dual instances of postfix if any.
Open /etc/postfix/main.cf
and set inet to all.
Add the following to master.cf
transport1 unix - - n - 1 smtp
-o smtp_bind_address= (add a space at 1st)
-o syslog_name=postfix-localroute1 (add a space at 1st)
Add/create the following to /etc/postfix/transport
somecompany.com transport1:
Run postmap after defining the transport file.
postmap /etc/postfix/transport
I have defined a transport above. It means all mail to #somecompany.com will go through you specifed in transport and that ip will not b displayed as it is in maillog. Instead it will be shown as postfix-localroute1
Add the following to main.cf
transport_maps = hash:/etc/postfix/transport
Run:postmap /etc/postfix/transport
Reload postfix:postfix reload

Change Exim file with WHM Cpanel

Hi i started using osTicket for my helpdesk and i was able to do the Email pipe successfully, but even if the ticket is created, the user receives: Mail delivery failed: returning message to sender.
In osTicket it says to change de exim document, but i have WHM and i don't know how to change it.
Can someone tell me how to change the following using the WHM editor
driver = pipe
return_output
driver = pipe
group = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"
return_output
user = "${lookup{$domain}lsearch* {/etc/userdomains}{$value}}"
i need to change the return_output to return_fail_output
Sounds like you need to change your EXIM config file. In WHM, you can go to: Service Configuration -> Exim Configuration and click on 'Advanced Editor' (at the bottom) to have access to it.
I will warn to be careful in there as it may cause issues, but that's where it looks like you'll want to put your rules and such.

Catchall Router on Exim does not work

I have setup a catchall router on exim (used as last router):
catchall:
driver = redirect
domains = +local_domains
data = ${lookup{*#$domain}lsearch{/etc/aliases}}
retry_use_local_part
This works perfectly when sending emails locally. However, if I login to my GMail account and send an email to whatever#mydomain.com, then I get an "Unrouteable Address".
Thank you for any hints to solve this issue.
In the system_aliases: section of the config file you already have a section which does the lookup in /etc/aliases.
Replace
data = ${lookup{$local_part}lsearch{/etc/aliases}}
with
data = ${lookup{$local_part}lsearch*#{/etc/aliases}}
and make sure you have *:catchall_username* in /etc/aliases
This works great for a single domain mail server which is already using /etc/aliases
For this router to work, make sure that
mydomain.com is in local_domains
there is an entry for *#mydomain.com in /etc/aliases
MX record for mydomain.com is pointing to the server, where you've
configured this
This is old as heck, but I didn't see a good answer posted and someone else might want to know the answer.
This post is geared towards Debian with in single configuration file mode. It should work on any Linux Exim4 install though. For the purpose of explaining things we’ll use test#example.com which is configured with the hostname mail.example.com. The system will have a real user called test and we want to create an alias for test called alias. So the end result will all email sent to alias#example.com forwarded to test#example.com without having to create the user alias on the system.
First we need to create a place to store all of the alias files:
mkdir /etc/exim/aliases.d
vim /etc/exim/aliases.d/mail.example.com
contents of the alias file for mail.example.com alias:test
vim /etc/exim/exim4.conf.template
Now look for the section system_aliases. Here you’ll see data = ${lookup{$local_part}lsearch{/etc/aliases}} or something similar. Change that to
data = ${lookup{$local_part}lsearch{/etc/exim4/aliases.d/$domain}}
Save the file and restart exim. The alias should now work. To add support for other domains just add more alias files in the aliases.d directory with the correct hostname.
I copied and pasted this from my blog:
0xeb.info