>
>I have qmail set up to recieve mail from a few different virtual domains.
For most of >them, I have all mail sent to those domains forwarded to one
e-mail account (a hotmail >account) using .qmail files. I would like to
prepend the message so that when I read the >body of the message using
hotmail, I can tell which account it was originally sent to >before it was
forwarded. It would look smoething like this:
>
>Originally sent to : [EMAIL PROTECTED]
>
>And then the real body of the message...
>
>I assume this would be done in the .qmail file before the forward command,
but how?
>
I am sure there's more than one way to do it. Here's a little perl script
that you can tailor to your needs. I am going to use it for a number of
users that will have their domain name changed next week, so the hotmail.com
part is still from my tests...
In the alias/.qmail* files of those users, I have:
[root@yuclnx2 alias]# cat .qmail-lsrrsl
|/usr/local/bin/friendly-bounce.pl
I am pretty sure what you (and I) are trying to achieve is also possible
with a program called 'vacation'. I just wasn't able to bounce the mail AND
forward it to the new reciepient at the same time from the .qmail* file.
-Filip
#!/usr/bin/perl
use Net::SMTP;
$mail_server = "212.8.180.36";
$domain_to_forward_to = "hotmail.com";
$message_bounce = "This email address has recently changed. Please
send all future mail to:\n";
$message_forward = " tried to mail you using your old email
address.\n\n\n";
$new_recipient = $ENV{'RECIPIENT'};
($new_recipient, $fake_dom) = split(/\@/, $new_recipient);
$new_recipient = $new_recipient . "\@" . $domain_to_forward_to;
while ($line = <STDIN>) { $mail_to_attach = $mail_to_attach . $line; }
# Bounce mail to original sender
#
$smtp_bounce = Net::SMTP->new($mail_server);
$smtp_bounce->mail("antwerpen.be-redirect\@yucom.be");
$smtp_bounce->to($ENV{'SENDER'});
$smtp_bounce->data();
$smtp_bounce->datasend("From: antwerpen.be mail bouncer\n");
$smtp_bounce->datasend("Subject: bounced email - please update your contacts
info\n\n");
$smtp_bounce->datasend($message_bounce . $new_recipient . "\n\n\n" .
$mail_to_attach);
$smtp_bounce->dataend();
$smtp_bounce->quit;
# Forward mail to real recipient's new email address
#
$smtp_forward = Net::SMTP->new($mail_server);
$smtp_forward->mail("antwerpen.be-redirect\@yucom.be");
$smtp_forward->to($new_recipient);
$smtp_forward->data();
$smtp_forward->datasend("From: antwerpen.be mail bouncer\n");
$smtp_forward->datasend("Subject: forwarded email - someone used an outdated
email address\n\n\n");
$smtp_forward->datasend($ENV{'SENDER'} . $message_forward .
$mail_to_attach);
$smtp_forward->dataend();
$smtp_forward->quit;