re-sending received mail to new alias map

2016-11-29 Thread troy_postfix
I have a virtual user on a virtual mailbox domain, let's say u...@domain.com
and their mail has been received into /var/mail/vhosts/domain.com/user for
some time.  They only just pointed out that they no longer have access to
that mailbox remotely via IMAP.  I've set up an alias map so that mail sent
to u...@domain.com now goes to her home ISP email address
user@isp_domain.com

But for mail already sitting on the server here, what's the best way to
forward (re-queue?) all of that to her user@isp_domain.com?  There are
thousands of emails.

-- 
Troy Piggins



Re: re-sending received mail to new alias map

2016-11-29 Thread Viktor Dukhovni

> On Nov 29, 2016, at 8:18 PM, troy_post...@piggo.com wrote:
> 
> But for mail already sitting on the server here, what's the best way to
> forward (re-queue?) all of that to her user@isp_domain.com?  There are
> thousands of emails.

Given that you know the envelope recipient, you need to re-inject this
back into the mailstream for delivery via the sendmail(1) command, and
carefully specify the new envelope recipient on the command-line, making
sure to not revive any other (header) recipients.

Use the user's old address as the envelope sender in order to avoid SPF
issues.  So the minimum command to forward a single message file is:

/usr/sbin/sendmail -f "user@here" -i -- "user@there" < msgfile

However, depending on what headers your email system prepends, it may
be prudent to strip any locally added "Delivered-To:", "X-Original-To:"
and similar headers.

Don't send everything at once.  Send a couple of test messages and
check with the user that they are arriving intact.

Even then send the mail slowly, don't flood the users mailbox, the
downstream MTA may object to excessive arrival rates for a single
user.

That said, the best approach is to give the user temporary IMAP
access, so that the user can download any missed email, and not
forward it all.  Or provide access to a tarball with all the
messages, ...  Forwarding can run into obstacles with DMARC,
anti-spam controls, ...

-- 
Viktor.