Change reception in postfix queue

After running postqueue -p i sometimes finds misspelled email-adresses,
is there a way to change the reception adress (envelop to adress) of the messages,
so it can be delivered.

exemple:

postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
A78C42189B1     2523 Thu Jul 25 14:53:57  [email protected]
                (connect to tellia.com[141.8.224.25]:25: Connection timed out)
                                         [email protected]
-- 2 Kbytes in 1 Request.

I want to pick upp A78C42189B1, and change the adress [email protected] to [email protected]


Solution 1:

So far i found out i can:

  1. using postcat -q A78C42189B1 i can get a copy of the queued item
  2. clean the message from meta data, the postcat messages may look like:

    *** ENVELOPE RECORDS deferred/A/A78C42189B1 ***
    message_size:            2523             248               2               0            2523
    message_arrival_time: Thu Jul 25 14:53:57 2013
    create_time: Thu Jul 25 14:53:57 2013
    named_attribute: rewrite_context=local
    sender_fullname: nobody
    sender: FROM:[email protected]
    original_recipient: [email protected]
    recipient: [email protected]
    *** MESSAGE CONTENTS deferred/A/A78C42189B1 ***
    
    mail headers...
    
    mail body...
    
    *** HEADER EXTRACTED deferred/A/A78C42189B1 ***
    named_attribute: notify_flags=1
    original_recipient: [email protected]
    done_recipient: [email protected]
    *** MESSAGE FILE END deferred/A/A78C42189B1 ***
    

    Clean out the postfix header and footer, so only mail headers and mail body is left in the file, using a text editor, or sed.

  3. use sendmail to send the mail to the new reciption

    sendmail [email protected] < edited_mail_file
    
  4. remove the original mail from the queue postsuper -d mailID

if someone with sed-skills, can cut out the mail header and body, the 3 first steps should be able to pipe togheter

Solution 2:

Yes, your described method is working with mail stuck in the mailqueue.

Though not really an answer to your specific issue, I'd like to share what I did to (re)solve some common misspelled domain-names in the future, using your hint:

In postfix/main.cf:

recipient_canonical_maps = regexp:/etc/postfix/maps/recipient_canonical

File /etc/postfix/maps/recipient_canonical:

/^(.*@)htomail.com$/ ${1}hotmail.com
/^(.*@)homail.com$/ ${1}hotmail.com
/^(.*@)hotmai.com$/ ${1}hotmail.com
/^(.*@)hotmai.co$/ ${1}hotmail.com
/^(.*@)hotma.com$/ ${1}hotmail.com
/^(.*@)gmial.com$/ ${1}gmail.com
/^(.*@)gmail.co$/ ${1}gmail.com
/^(.*@)gmail.nl$/ ${1}gmail.com