How do I forward and autoreply to incoming emails?

77

Solution 1

I expect you want to fake a bounce message on the old domain. I use Exim and their is a control to do this.

You will also want a clear bounce message that indicates that the email was accepted for delivery, but future messages should be sent to the new address.

Exim also allows for custom bounce messages in the aliases file. This can be used to specify the new address.

Postfix or exchange may have similar functionality.

EDIT: Exim documentation is quite good. See the specification chapter 40 (Access Control Lists) and Chapter 11 (String Expansions) for details related to your issue.

You could try an entry in the recipient ACL something like this:

warn
    domains = old.example.com
    control == fakereject/User ${local_part}@old.example.com has moved \
          ${local_part}@new.example.net\n\
          Your message has been forwarded to their new address.

Redirecting to your new server can be done by individual aliases, a redirect router (see chapter 22 section 3), or a rewrite rule (see chapter 31 Address rewiting) such as:

*@old.example.com      [email protected]     T

Solution 2

I would do that with Postfix and Cyrus-Imapd. Postfix would just forward everything to cyrus-imapd, and then you can use a Sieve Filter to :

  1. Forward the email to the new recipient
  2. Send a notification to the sender

From the top of my head, I think you could do it like that:

if header :contains "to" "user@old_domain.com" {
        redirect "user@new_domain.com";
        reject "old_domain.com is not used anymore, please send your emails to new_domain.com";
}

The difficulty is that Sieve rules are defined for each user, so you need to create a set of rules for each of your user. But you can easily script it.

More information about Sieve in Cyrus-Imapd can be found here: http://wiki.linuxwall.info/doku.php/en:ressources:astuces:sieve

Share:
77

Related videos on Youtube

Geordie Todd
Author by

Geordie Todd

Updated on September 18, 2022

Comments

  • Geordie Todd
    Geordie Todd over 1 year

    I am having 2 main issues. the first is I cannot make it loop back around for another persons details to be input. the second is I cannot get the shortestHight or shortestName to be recorded. (This is an assignment, I would like help and not the answer please)

          {
              System.out.println("Do you want to enter another person? Y/N ");
              answer = KB.next();
    
              while ("yes".equals(answer) || "Yes".equals(answer));
    
    
              System.out.println("Enter a Name ");
              name = KB.next();
              System.out.println("Enter " + name + "'s hight in meters");
              hight = KB.nextFloat();
              while (hight <= 0.8 || hight >= 2.5) 
              {
                  System.out.println(name + "must be between 0.8 and 2.5 meters");
                  System.out.println("Enter " + name + "'s hight in meters");
                  hight = KB.nextFloat();
              }
          }
    
    
          if (hight >= tallestHight) 
          {
              tallestHight = hight;
              tallestName = name;
          }
    
    
          else if (hight <= shortestHight) 
          {
              shortestHight = hight;
              shortestName = name;
          }
    
    
          System.out.println("The tallest persone is " + tallestName + " at a hight of " + tallestHight);
    
          System.out.println("And The shortest persone is " + shortestName + " at a hight of " + shortestHight);
    
      }
    }
    
    • PakkuDon
      PakkuDon over 9 years
      Not related to your question, but you could just use String#equalsIgnoreCase.
    • Yann
      Yann over 9 years
      I think you cut off the while when copy pasting above the "do you want to enter another person, that could be important
    • ljacqu
      ljacqu over 9 years
      while ("yes".equals(answer) || "Yes".equals(answer)); This will just loop over and over without doing anything. It's equivalent to while(...) { }
    • EpicPandaForce
      EpicPandaForce over 9 years
      You should use while ("yes".equals(answer) || "Yes".equals(answer)) { .... }
    • Seyf
      Seyf over 9 years
      while ("yes".equals(answer) || "Yes".equals(answer)); this loop is useless. it wants you to say yes to do nothing.
  • miroque
    miroque about 13 years
    Unfortunately, I can't do this in Google Apps without giving everyone an old_domain.com email address (in addition to their new_domain.com email address). It's way too confusing for most people unfortunately.
  • miroque
    miroque about 13 years
    Do you know of any documentation on how to do this?
  • Geordie Todd
    Geordie Todd over 9 years
    Thank you, I was able to use this and make some minor adj for ease of reading/understanding. As for the shortest I used another if statement similar to if (tallestHight == 0 && shortestHight == 0) so the first input was recorded into both tallest and shortest.
  • Michał Schielmann
    Michał Schielmann over 9 years
    @GeordieTodd no problem, glad I could help:)
  • Rowland Shaw
    Rowland Shaw almost 7 years
    You really need to explain how to do it...