0

I have a setup postfix/dovecot/mysql on Centos 6.5 following the guide at DigitalOcean.

I have virtual addresses and aliases working just fine, and now I am trying to add a donotreply alias.

In my virtual users table I have an entry for donotreply@mydomain.com with a destination of devnull.

At the end of /etc/aliases I have

devnull: /dev/null

I ran newaliases after this.

Checking the virtual alias :

$ postmap -q donotreply@mydomain.com mysql:/etc/postfix/mysql-virtual-alias-maps.cf 
devnull

When I send mail to this address I get a 'user doesn't exist' bounce for devnull@mydomain.com

Mar 25 14:48:12 vps1 postfix/lmtp[7686]: 8543360392: to=<devnull@mydomain.com>, orig_to=<donotreply@mydomain.com>, relay=host.mydomain.com[private/dovecot-lmtp], delay=0.14, delays=0.07/0.01/0.01/0.05, dsn=5.1.1, status=bounced (host host.mydomain.com[private/dovecot-lmtp] said: 550 5.1.1 <devnull@mydomain.com> User doesn't exist: devnull@mydomain.com (in reply to RCPT TO command))

Postfix (and dovecot) have been reloaded after every change, and still no luck.

My postfix conf :

$ postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
milter_default_action = accept
milter_protocol = 2
mydestination = localhost
myhostname = host.mydomain.com
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
non_smtpd_milters = $smtpd_milters
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_milters = inet:127.0.0.1:8891
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /path/to/ssl/cert
smtpd_tls_key_file = /path/to/ssl/privatekey
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 550
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp

I also tried enabling local recipient maps in /etc/postfix/main.cf

local_recipient_maps = unix:passwd.byname $alias_maps

but that didn't work either.

I also created a devnull local user

$ useradd -M -d /dev/null -s /sbin/nologin devnull

but that also changed nothing.

How do I get a virtual alias to redirect to /dev/null?

1

Also you can use DISCARD

DISCARD optional text...

Claim successful delivery and silently discard the message. Log the optional text if specified, otherwise log a generic message.

smtpd_recipient_restrictions =
 check_recipient_access hash:/etc/postfix/virtual_access
 reject_unknown_recipient_domain
 permit_mynetworks
 permit_sasl_authenticated
 reject_unauth_destination

# cat virtual_access
no-reply@example.net DISCARD DEV-NULL

# postmap virtual_access

Send a simple message

# echo "Hello world" | swaks -4 --server localhost --from alex@example.net --to no-reply@example.net --h-Subject "Test message" --body -
=== Trying localhost:25...
=== Connected to localhost.
<-  220 smtp.example.net ESMTP Postfix
 -> EHLO jenkins.example.net
<-  250-smtp.example.net
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-AUTH LOGIN PLAIN
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250 DSN
 -> MAIL FROM:<alex@example.net>
<-  250 2.1.0 Ok
 -> RCPT TO:<no-reply@example.net>
<-  250 2.1.5 Ok
 -> DATA
<-  354 End data with <CR><LF>.<CR><LF>
 -> Date: Mon, 28 Mar 2016 09:09:50 +0000
 -> To: no-reply@example.net
 -> From: alex@example.net
 -> Subject: Test message
 -> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
 ->
 -> Hello world
 ->
 ->
 -> .
<-  250 2.0.0 Ok: queued as 835721C7EBD
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

Check maillog

Mar 28 09:09:46 ci postfix/postfix-script[16971]: starting the Postfix mail system
Mar 28 09:09:46 ci postfix/master[16972]: daemon started -- version 2.6.6, configuration /etc/postfix
Mar 28 09:09:50 ci postfix/smtpd[16978]: connect from localhost[127.0.0.1]
Mar 28 09:09:50 ci postfix/smtpd[16978]: NOQUEUE: discard: RCPT from localhost[127.0.0.1]: <no-reply@example.net>: Recipient address DEV-NULL; from=<alex@example.net> to=<no-reply@example.net> proto=ESMTP helo=<jenkins.example.net>
Mar 28 09:09:50 ci postfix/smtpd[16978]: 835721C7EBD: client=localhost[127.0.0.1]
Mar 28 09:09:50 ci postfix/smtpd[16978]: disconnect from localhost[127.0.0.1]
  • Double thanks - your solution works for me and swaks makes it far easier to test than just a raw smtp session with telnet. – Chris C Mar 28 '16 at 13:08

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.