Redirect emails based on the extention with postfix

I have email alias called reports which I like to redirect to a default subset of emails. But I’m looking to implement something like sending emails to reports+reportName and have a different subset of emails which I redirect to, And in case there is no rule for reports+reportName it will default to reports.

reports: user1, user2
reports+xxx: user3, user4

  • Sending a mail to reports+xxx@ will go to user3 & user4
  • Sending a mail to reports+yyy@ (which is not exists) will go to user1 & user2

I found a way using a local account with .forward+EXT files, but I like to under option where I can manage the redirect/overwrites in single file.

email – Configure Postfix to rewrite outgoing mail From address for specific recipients

I have an application which sends out email via a local Postfix v2.10.1, which relays mail via another SMTP host.

Is it possible to configure Postfix to rewrite a specific From address for emails to certain recipients?

For example, if…

  • From address = support@example.com
  • To address = foo@example.org or bar@example.net

Then rewrite the From address to noreply@example.com instead.

Postfix change “From: ” address when redirecting received email

When redirected, received email from my server preserves the original "From: " address, which isn’t favorable since that address may (and usually do) have SPF protected domain, among other reasons.

This looks like:

  • a mail is sent from forexampleaddr@gmail.com to email address name@domain.tld hosted at my server,

  • a mail is delivered to name@domain.tld

  • a mail is forwarded to othername@otherdomain.tld. otherdomain.tld rejects the email since my server isn’t eligible to send @gmail.com emails.

How can I deal with this: can I rewrite “From: ” address but only in case when email is redirected and according to some map?


It is a standard Virtualmin email setup with Postfix and /etc/aliases.

virtual_alias_maps = hash:/etc/postfix/virtual
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

/etc/postfix/virtual

name@domain.tld    name.domain

/etc/aliases

# See man 5 aliases for format
postmaster:    root
clamav: root


name.domain: othername@otherdomain.tld,name.domain

Sending emails to Postfix mail server using phpmailer from another server

I have:
erp.domain.com (Example:35.161.23.2) Ubuntu apache2 phpmailer
mail.domain.com (Example:52.10.42.40) Ubuntu apache2 postfix

All working but alone.

My problem when trying to use phpmailer to send emails to domain.com

I added , 35.161.23.2 to /etc/postfix/main.cf in “mynetworks =” line
but phpmailer say error

Note: When I send to another mail it works fine.

send – postfix repeatedly sending emails – message may be sent more than once

I added two emails of our new members to a mailing list on our Debian/postfix machine (used just to send emails to our members). They complained about receiving hundreds of emails from our machine, and unfortunately it is true, I found another two users with different domain (we have ~10k members total without problems).

This is what I found in mail.log:

  1: Feb 23 06:25:24 m2 postfix/smtp(26117): 38F5020EB4: to=<mail4@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=71848, delays=71222/0.03/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
 15: Feb 23 06:30:23 m2 postfix/smtp(26224): 3595420E53: to=<mail1@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=77167, delays=76542/0.04/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
 53: Feb 23 06:50:24 m2 postfix/smtp(26943): C02C420E63: to=<mail3@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=76640, delays=76014/0.01/26/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
170: Feb 23 07:25:24 m2 postfix/smtp(27635): A1F4C20E26: to=<mail2@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=81552, delays=80927/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
244: Feb 23 07:45:23 m2 postfix/smtp(28025): 38F5020EB4: to=<mail4@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=76648, delays=76022/0.04/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
250: Feb 23 07:50:23 m2 postfix/smtp(28165): 3595420E53: to=<mail1@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=81967, delays=81342/0.01/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
306: Feb 23 08:10:24 m2 postfix/smtp(28558): C02C420E63: to=<mail3@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=81440, delays=80814/0.01/26/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
431: Feb 23 08:45:23 m2 postfix/smtp(29315): A1F4C20E26: to=<mail2@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=86352, delays=85726/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
467: Feb 23 09:05:23 m2 postfix/smtp(29745): 38F5020EB4: to=<mail4@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=81448, delays=80822/0.01/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
484: Feb 23 09:10:23 m2 postfix/smtp(29830): 3595420E53: to=<mail1@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=86768, delays=86142/0.01/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
553: Feb 23 09:30:24 m2 postfix/smtp(30267): C02C420E63: to=<mail3@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=86240, delays=85614/0.03/26/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
672: Feb 23 10:05:25 m2 postfix/smtp(30949): A1F4C20E26: to=<mail2@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=91154, delays=90527/0.02/26/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
731: Feb 23 10:25:24 m2 postfix/smtp(31385): 38F5020EB4: to=<mail4@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=86248, delays=85622/0.01/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
746: Feb 23 10:30:24 m2 postfix/smtp(31493): 3595420E53: to=<mail1@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=91568, delays=90943/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
817: Feb 23 10:50:24 m2 postfix/smtp(31933): C02C420E63: to=<mail3@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=91040, delays=90413/0.03/25/601, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
927: Feb 23 11:25:24 m2 postfix/smtp(32608): A1F4C20E26: to=<mail2@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=95953, delays=95327/0.01/26/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
997: Feb 23 11:45:23 m2 postfix/smtp(533): 38F5020EB4: to=<mail4@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=91048, delays=90422/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
1009: Feb 23 11:50:24 m2 postfix/smtp(675): 3595420E53: to=<mail1@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=96368, delays=95743/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
1080: Feb 23 12:10:23 m2 postfix/smtp(1086): C02C420E63: to=<mail3@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=95839, delays=95213/0.01/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
1177: Feb 23 12:45:24 m2 postfix/smtp(1790): A1F4C20E26: to=<mail2@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=100753, delays=100127/0.01/26/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
1229: Feb 23 13:05:24 m2 postfix/smtp(2209): 38F5020EB4: to=<mail4@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=95848, delays=95222/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
1251: Feb 23 13:10:24 m2 postfix/smtp(2302): 3595420E53: to=<mail1@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=101168, delays=100543/0.05/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)
1330: Feb 23 13:30:24 m2 postfix/smtp(2717): C02C420E63: to=<mail3@domain2.com>, relay=mail.mailserver2.com(5.6.7.8):25, delay=100640, delays=100014/0.04/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver2.com(5.6.7.8) timed out while sending end of data -- message may be sent more than once)
1410: Feb 23 14:05:23 m2 postfix/smtp(3399): A1F4C20E26: to=<mail2@domain1.com>, relay=mail.mailserver1.com(1.2.3.4):25, delay=105552, delays=104927/0.02/25/600, dsn=4.4.2, status=deferred (conversation with mail.mailserver1.com(1.2.3.4) timed out while sending end of data -- message may be sent more than once)

The server is re-sending the emails in an endless loop, spamming users every 1,5 hour, probably until maximal_queue_lifetime is reached. This is of course a huge problem for us, so I have a few questions here:

1, I don’t think it is our postfix’s problem, it is just 4 users (2 mailservers) of 10k. Anyway, has anyone seen this and is it possible to fix it? All I could find is info about old/bad cisco routers on recipients side, MTU problem and Packet fragmentation/FW problem somewhere on the way. I know this is probably a problem on the recipient server, but it is not under our possession, so no fixes are possible there.

2, Postfix knows the message is sent more than once, it even writes it in the log. How can I force postfix to not spam mailboxes and whenever it knows the message may be sent more then once, just consider it delivered and/or remove it from the queue. Just these, not all deferred. I don’t care if some other emails would not be delivered because of this.

3, especially if (2) is not possible, is it possible to disable retries of deferred emails to a specific domain/mailserver?

Or is there any other thing to do to solve this?

thank you

Is it possible to accept messages in Postfix that are sent to an invalid email address?

I have a Postfix server running and receiving email for “MyDomain.com”. I am wondering if it is possible to configure Postfix to accept email for any address sent to it. For example, could I configure it to accept messages sent to ThisAddressDoesNotExist@mydomain.com? Right now when I do this, the message bounces.

linux – Setting up Postfix relay server through google apps

[Image description of out environment][1]
[1]: https://i.stack.imgur.com/hdzs7.png

hi all,
first of all i want to let you know about our environment.
we have Multiple servers and different services are hosted on them, we are using G-suite enterprise hosting so don’t own our own server.
as we have to send automated alerts from different service for example erp related alerts, zabbix server alerts web server alerts internal and outside of organization, we need to setup our own SMTP server.
i came to know that we can do this by using SMTP relay server but i am confused on procedure to set it up.
can anyone share any reference to setting it up. i have attached snapshot for your reference

ssmtp – Postfix is trying to every email to the sender host

Postfix is trying to send email to the recipient as well as the sender host itself. For example I’m sending the email from server001 and when I check postfix logs, it sends to the recipient as well as the server hostname.

server001 is configured to use ssmtp to forward all emails to postfix server.

(root@server001)#mail -v -s "test"  user@gmail.com </dev/null


(root@postfix-server-001)# tail -f /var/log/maillog

Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/cleanup(172): EC813D: message-id=<>
Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/qmgr(98): EC813D: from=<no-reply@example-inc.com>, size=343, nrcpt=2 (queue active)
Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/smtpd(169): disconnect from unknown(10.60.1.41) helo=1 mail=1 rcpt=2 data=1 quit=1 commands=6
Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/smtp(173): EC813D: replace: header From: "root" <no-reply@example-inc.com>: From: "example Inc" <no-reply@example-inc.com>
Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/smtp(173): EC813D: to=<user@gmail.com>, relay=10.49.64.5(10.49.64.5):25, delay=0.67, delays=0.08/0/0.32/0.27, dsn=2.0.0, status=sent (250 Ok 01010177963957e0-ca8b32ae-255d-4577-a5b6-38d5bf4421d3-000000)
Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/smtp(173): EC813D: to=<test@server001>, relay=10.49.64.5(10.49.64.5):25, delay=0.67, delays=0.08/0/0.32/0.27, dsn=2.0.0, status=sent (250 Ok 01010177963957e0-ca8b32ae-255d-4577-a5b6-38d5bf4421d3-000000)
Feb 12 12:31:16 postfix-deployment-6bb56cc4fb-hlx5c postfix/qmgr(98): EC813D: removed

postfix – SMTP Untrusted TLS connection still sending emails

When sending mail from my client through a mail server that is then using AWS SES as a mail relay I’m seeing this in the postfix log as each message moves through:

smtp: Untrusted TLS connection established to email-smtp.us-west-1.amazonaws.com(13.57.144.53):587: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
smtp: D34E420866249C: to=<recipient@domain.tld>, relay=email-smtp.us-west-1.amazonaws.com(13.57.144.53):587, delay=0.81, delays=0/0.11/0.52/0.17, dsn=2.0.0, status=sent (250 Ok 0111017774953167-f6df400f-aa87-43ab-8ca6-6c5534c50e17-000000)

If the connection is “untrusted” but SES requires TLS (which is set up, though perhaps not correctly) for security why are messages still sent on.

Things are working… I’m just surprised that they are.

I followed AWS’s SES with Postfix docs. Main difference with my setup is I couldn’t use smtp_tls_security_level = encrypt, as suggested, because that was blocking inbound smtpd transactions. Setting it back to smtp_tls_security_level = may gets the mail through but logs say smtp is “untrusted” even though connection seems to succeed?!? Not sure if these are related but that’s all I got.

Anything I can fix/improve?

email – How do you instruct Postfix to use SMTP over a different port?

I’m operating a Postfix server, and my local network has port 25 blocked. I’ve tried everything I can to in order to get port 25 unblocked – no dice.

Unlike this I don’t want to proxy my data. (Haven’t found a good way to do it since I don’t have external servers) I’d rather just send stuff over port 587 instead of 25 – since 587 isn’t blocked for some reason.

How exactly do I go about setting my postfix config to send emails on port 587? I’m fairly sure the hosts I’ll be sending to support port 587. An alternative could be proxying if it still sends from the email account on my server, is free, and doesn’t use OAuth2 (I’m specifically setting this up because of misconfiguration of platforms like Outlook, and Gmail demanding OAuth2).

I’d like to note that I’m using Ubuntu 20.04 LTS as my server base – so CentOS/RHEL tricks won’t work.