1

There's several answers on here about how to configure postfix to redirect all messages to a single mailbox, for development/testing of mail scripts.

I'm looking for a variation on this where I open an alternate port on an existing mail server, and I want all SMTP messages delivered to that port to get dumped into a mailbox (Dovecot, via local delivery) on that same server.

My problem is that smtpd shares the configuration in main.cf, and I don't see a way to run a second copy of smtpd without configuring an entire separate postfix environment. I'm looking for a simpler solution.

The smtp-sink program is almost exactly what I want. It writes each message to a new file, but I would additionally like them pushed over local delivery to Dovecot where my mail client can conveniently see them.

Can anyone recommend a simple way to make this happen? I'll even accept a perl script that listen/reads SMTP and writes LMTP.

  • What problem is this meant to solve? See meta.stackexchange.com/q/66377/189912 – Michael Hampton Sep 25 '15 at 4:54
  • For delivery, do you want use dovecot LMTP or postfix local service? – masegaloeh Sep 25 '15 at 5:36
  • 1
    I want to solve the problem of redirecting email I generate from dev machines to a mailbox where I can quickly view the email (complete with real-world to/from/cc headers) in a standard mail client, but without a bunch of infrastructure that I have to maintain. I want to be able to direct outbound SMTP of my dev projects to this destination with minimal hassle. And I want minimal complexity so it doesn't explode on me by accident. – M Conrad Sep 25 '15 at 6:58
  • @masegaloeh - I have postfix configured with local_transport = lmtp:unix:private/dovecot-lmtp. I'm not sure if that bypasses local, or is a setting used by local. If it is used by local then an answer with postfix local would be preferred, because it's one less duplicated configuration setting. – M Conrad Sep 25 '15 at 7:16
  • 2
    If you configure smtp-sink to write messages to the user/Maildir/new/ directory inside the dovecot storage then they should appear in your inbox. Just make sure they're written with the right owner/group. – wurtel Sep 25 '15 at 7:46
3

You can override smtpd_recipient_restrictions on secondary port (for example port 9925) so it REDIRECT email to your selected mailbox (for example dumpbin@example.com).

The entry of master.cf

9925      inet  n       -       -       -       -       smtpd
    -o smtpd_recipient_restrictions=check_recipient_access,pcre:/etc/postfix/x.pcre,reject_unauth_destination

File /etc/postfix/x.pcre

/.*/    REDIRECT dumpbin@example.com

With this setup, every email coming to this port will match PCRE pattern on /etc/postfix/x.pcre, therefore postfix will REDIRECT it to dumpbin@example.com.

Your last task is ensure that dumpbin@example.com was delivered via dovecot LMTP.

  • This doesn't quite work... I'm running Postfix 3.0.1, and when I try this I get "Relay Access Denied". I tried removing the options that deny relaying but it gives me fatal: in parameter smtpd_relay_restrictions or smtpd_recipient_restrictions, specify at least one working instance of: reject_unauth_destination, defer_unauth_destination, reject, defer, defer_if_permit or check_relay_domains. I tried overriding the virtual_alias_maps but it doesn't seem to take effect. Looks like rewriting happens from a separate service, before the smtp relay checks occur. – M Conrad Oct 2 '15 at 5:56
  • Woops, forgot to add that mandatory parameter... See the edit – masegaloeh Jun 2 '16 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.