Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

user*@example.com wildcard, virtusertable

250 views
Skip to first unread message

VM3139

unread,
Dec 4, 2012, 3:56:30 PM12/4/12
to
Hi everyone,

I'd like to have every e-mail sent to user*@example.com to be forwarded to local a mailbox on the same server called user_prod.

This could be userabc, user_xyz, user309, etc. All of these users are non existent, except for user_prod. I am using sendmail with cyrus mailbox store.

At the moment I have the following in virtusertable

@example.com user_prod

which works great but matches all e-mails sent to the example.com domain. I need to match only ones beginning with user.

All suggestions are welcome. Thanks for your time.

Loki Harfagr

unread,
Dec 4, 2012, 4:51:31 PM12/4/12
to
Tue, 04 Dec 2012 12:56:30 -0800, VM3139 did cat :
check "use_cw_file" ("class w" family)

you may see that usually in /usr/share/sendmail/cf/README
or explore the fine manual in op.me (cd /usr/doc/sendmail-8.*/op/)

Claus Aßmann

unread,
Dec 4, 2012, 6:59:36 PM12/4/12
to
VM3139 wrote:

> I'd like to have every e-mail sent to user*@example.com to be forwarded to local a mailbox on the same server
> called user_prod.

That doesn't work with a standard setup. However, you can
- use user+whatever (works out of the box), or
- write your own custom rules using a regex map to rewrite
the addresses.

Carl Byington

unread,
Dec 4, 2012, 7:40:30 PM12/4/12
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 04 Dec 2012 21:51:31 +0000, Loki Harfagr wrote:

> Tue, 04 Dec 2012 12:56:30 -0800, VM3139 did cat�:

>> At the moment I have the following in virtusertable
>>
>> @example.com user_prod
>>
>> which works great but matches all e-mails sent to the example.com
domain. I need to match only ones beginning with user.


> check "use_cw_file" ("class w" family)

> you may see that usually in /usr/share/sendmail/cf/README
> or explore the fine manual in op.me (cd /usr/doc/sendmail-8.*/op/)


I don't see where changing class w helps the OP.

VM3139 - you could write a socket map for users, then in sendmail.mc,

define(`LUSER_RELAY')

LOCAL_CONFIG
Kusermap socket local:/some/path/your.user.map.sock

LOCAL_RULESETS
SLocal_localaddr
# Detect valid user names
R$+ $: $1 <$(usermap $1 $: $)>
R$+ <$+> $#local $@ $2 $: @ user_prod
# Treat remaining as usual
R$* $@


Or you could write a small milter that rejects any username that does
not match user.*

I think the milter approach is cleaner.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iEYEARECAAYFAlC+l1kACgkQL6j7milTFsE4SACeLjtmqrFBLLQBMsdXsfzT0I81
j2cAn1TgCKaIZSTbCIEt6THnHoobCHOK
=jjd2
-----END PGP SIGNATURE-----

Loki Harfagr

unread,
Dec 5, 2012, 2:41:25 AM12/5/12
to
Wed, 05 Dec 2012 00:40:30 +0000, Carl Byington did cat :

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tue, 04 Dec 2012 21:51:31 +0000, Loki Harfagr wrote:
>
>> Tue, 04 Dec 2012 12:56:30 -0800, VM3139 did cat�:
>
>>> At the moment I have the following in virtusertable
>>>
>>> @example.com user_prod
>>>
>>> which works great but matches all e-mails sent to the example.com
> domain. I need to match only ones beginning with user.
>
>
>> check "use_cw_file" ("class w" family)
>
>> you may see that usually in /usr/share/sendmail/cf/README
>> or explore the fine manual in op.me (cd /usr/doc/sendmail-8.*/op/)
>
>
> I don't see where changing class w helps the OP.

:$ neither do I now that I read his question again and understood his request!
Sorry :$

VM3139

unread,
Dec 5, 2012, 7:05:24 AM12/5/12
to
Thanks.

Does not work for some reason folks. I've created /var/run/usermap.sock using mksock and tried e-mailing user...@example.com. See maillog & sendmail.mc bellow:

Dec 5 05:55:27 ip-10-244-179-198 sendmail[30015]: qB5BtQQt030015: from=ec2-user, size=205, class=0, nrcpts=1, msgid=<201212051155....@ip-10-244-179-198.ec2.internal>, relay=root@localhost
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30016]: STARTTLS=server, relay=localhost [127.0.0.1], version=TLSv1/SSLv3, verify=NO, cipher=DHE-RSA-AES256-SHA, bits=256/256
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30015]: STARTTLS=client, relay=[127.0.0.1], version=TLSv1/SSLv3, verify=FAIL, cipher=DHE-RSA-AES256-SHA, bits=256/256
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30016]: qB5BtRRD030016: from=<ec2-...@ip-10-244-179-198.ec2.internal>, size=516, class=0, nrcpts=1, msgid=<201212051155....@ip-10-244-179-198.ec2.internal>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Dec 5 05:55:27 ip-10-244-179-198 mimedefang.pl[29687]: qB5BtRRD030016: MDLOG,qB5BtRRD030016,mail_in,,,<ec2-...@ip-10-244-179-198.ec2.internal>,<user...@example.com>,
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30015]: qB5BtQQt030015: to=user...@example.com, ctladdr=ec2-user (222/500), delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=30205, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (qB5BtRRD030016 Message accepted for delivery)
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: accepted connection
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: lmtp connection preauth'd as postman
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: verify_user(user.user3338) failed: Mailbox does not exist
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30019]: qB5BtRRD030016: to=<user...@example.com>, delay=00:00:00, xdelay=00:00:00, mailer=cyrusv2, pri=120516, relay=localhost, dsn=5.1.1, stat=User unknown
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30019]: qB5BtRRD030016: qB5BtRRC030019: DSN: User unknown
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: IOERROR: fstating sieve script /var/lib/imap/sieve/e/ec2-user/defaultbc: No such file or directory
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: duplicate_check: <201212051155....@ip-10-244-179-198.ec2.internal> user.ec2-user 0
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: duplicate_check: <201212051155....@ip-10-244-179-198.ec2.internal> user.ec2-user 0
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: Delivered: <201212051155....@ip-10-244-179-198.ec2.internal> to mailbox: user.ec2-user
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: mystore: starting txn 2147483740
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: mystore: committing txn 2147483740
Dec 5 05:55:27 ip-10-244-179-198 lmtpunix[30011]: duplicate_mark: <201212051155....@ip-10-244-179-198.ec2.internal> user.ec2-user 1354708527 14
Dec 5 05:55:27 ip-10-244-179-198 sendmail[30019]: qB5BtRRC030019: to=<ec2-...@ip-10-244-179-198.ec2.internal>, delay=00:00:00, xdelay=00:00:00, mailer=cyrusv2, pri=31879, relay=localhost [[UNIX: /var/lib/imap/socket/lmtp]], dsn=2.0.0, stat=Sent



divert(-1)dnl
include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
VERSIONID(`setup for linux')dnl
OSTYPE(`linux')dnl
define(`confDEF_USER_ID', ``8:12'')dnl
define(`confTO_CONNECT', `1m')dnl
define(`confTRY_NULL_MX_LIST', `True')dnl
define(`confDONT_PROBE_INTERFACES', `True')dnl
define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
define(`ALIAS_FILE', `/etc/aliases')dnl
define(`STATUS_FILE', `/var/log/mail/statistics')dnl
define(`UUCP_MAILER_MAX', `2000000')dnl
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
define(`confAUTH_OPTIONS', `A')dnl
define(`confCACERT_PATH', `/etc/mail/certs')dnl
define(`confCACERT', `/etc/mail/certs/CAcert.pem')dnl
define(`confSERVER_CERT', `/etc/mail/certs/MYcert.pem')dnl
define(`confSERVER_KEY', `/etc/mail/certs/MYkey.pem')dnl
define(`confCLIENT_CERT', `/etc/mail/certs/MYcert.pem')dnl
define(`confCLIENT_KEY', `/etc/mail/certs/MYkey.pem')dnl
define(`confTO_IDENT', `0')dnl
FEATURE(`no_default_msa', `dnl')dnl
FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
VIRTUSER_DOMAIN_FILE(`/etc/mail/virtual-domains')dnl
FEATURE(redirect)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(use_ct_file)dnl
FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl
FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
FEATURE(`blacklist_recipients')dnl
EXPOSED_USER(`root')dnl
define(`confLOCAL_MAILER', `cyrusv2')dnl
define(`CYRUSV2_MAILER_ARGS', `FILE /var/lib/imap/socket/lmtp')dnl

DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnl
DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl

FEATURE(`accept_unresolvable_domains')dnl
LOCAL_DOMAIN(`example.com')dnl

define(`LUSER_RELAY')

LOCAL_CONFIG
Kusermap socket local:/var/run/usermap.sock
LOCAL_RULESETS
SLocal_localaddr
# Detect valid user names
R$+ $: $1 <$(usermap $1 $: $)>
R$+ <$+> $#local $@ $2 $: @ albums_pics_reciever
# Treat remaining as usual
R$* $@


DOMAIN(generic)dnl
define(`confBAD_RCPT_THROTTLE', `3')dnl
define(`confMILTER_LOG_LEVEL',`1')dnl

INPUT_MAIL_FILTER(`mimedefang', `S=unix:/var/spool/MIMEDefang/mimedefang.sock, F=T, T=S:1m;R:1m')
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
MAILER(cyrusv2)dnl




Kees Theunissen

unread,
Dec 5, 2012, 12:28:55 PM12/5/12
to
From an other message in this thread I understand that you're using
mimedefang. So you can use mimedefang's functions
add_recipient($recip) and delete_recipient($recip) in your filter
to change a recipient address.

Regards,

Kees.

--
Kees Theunissen.


VM3139

unread,
Dec 5, 2012, 12:54:03 PM12/5/12
to
I'd like to match user*@ part before changing recipient address. Not sure how can I do this with mimedefang.

Kees Theunissen

unread,
Dec 5, 2012, 4:06:27 PM12/5/12
to
Add something like this to your filter_begin or filter_end function:


foreach my $recp (@Recipients) {
next if ( $recp =~ /^<?user_prod\@example\.com>?$/i );
if ( $recp =~ /^<?user.*\@example\.com>?$/i ) {
add_recipient('user...@example.com');
delete_recipient($recp);
}
}



regards,

Kees.

--
Kees Theunissen.

Carl Byington

unread,
Dec 5, 2012, 8:46:23 PM12/5/12
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 05 Dec 2012 04:05:24 -0800, VM3139 wrote:

> Does not work for some reason folks. I've created
> /var/run/usermap.sock
> using mksock and tried e-mailing user...@example.com. See maillog &
> sendmail.mc bellow:

Do you have a program listening on that socket? You will need to write
some code to listen on that socket and return the responses that
sendmail wants.

Claus suggested a regex map to rewrite the names - I have never used one
of those, but it is almost surely easier than trying to get the usermap
working.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iEYEARECAAYFAlC/+NUACgkQL6j7milTFsG8tACdGeuvno0sUKb75+z53xCVBpH+
MtsAn1qX6HHZHZMTz7y0R5gRn9sE7QVm
=qhTW
-----END PGP SIGNATURE-----

VM3139

unread,
Dec 6, 2012, 6:18:43 AM12/6/12
to
Kees, this worked wonderfully well.

Much appreciated.

This feature should be available in-the-box with sendmail (apart from the '+' sign wildcard) as it's quite useful in certain setups.



>
>
> --
>
> Kees Theunissen.

0 new messages