Linux mail forwarding

Linux mail forwarding!

In Linux, mail forwarding is the process of redirecting incoming email messages from one email address to another. This can be useful in various scenarios, such as:

  1. Redirecting email to a different account: If you have multiple email accounts, you can forward emails from one account to another.
  2. Forwarding email to a different domain: If you have an email account with a specific domain (e.g., example.com), you can forward emails to a different domain (e.g., example.net).
  3. Redirecting email to a different user: If you have multiple users on a Linux system, you can forward emails from one user to another.

Here are the general steps to set up mail forwarding in Linux:

Method 1: Using the procmail command

  1. Install procmail on your Linux system: sudo apt-get install procmail (on Ubuntu-based systems) or sudo yum install procmail (on RHEL-based systems).
  2. Create a .procmailrc file in your home directory with the following contents:
    
    :0
  1. Save the file and restart the procmail service: sudo service procmail restart (on Ubuntu-based systems) or sudo service procmail restart (on RHEL-based systems).

Method 2: Using the postfix command

  1. Install postfix on your Linux system: sudo apt-get install postfix (on Ubuntu-based systems) or sudo yum install postfix (on RHEL-based systems).

  2. Edit the /etc/postfix/main.cf file and add the following lines:

    virtual_alias_maps = hash:/etc/postfix/virtual
  3. Create a /etc/postfix/virtual file with the following contents:

    [email protected] [email protected]

    Replace [email protected] with the email address you want to forward from, and [email protected] with the email address you want to forward to.

  4. Save the file and restart the postfix service: sudo service postfix restart (on Ubuntu-based systems) or sudo service postfix restart (on RHEL-based systems).

Method 3: Using the fetchmail command

  1. Install fetchmail on your Linux system: sudo apt-get install fetchmail (on Ubuntu-based systems) or sudo yum install fetchmail (on RHEL-based systems).

  2. Create a .fetchmailrc file in your home directory with the following contents:

    poll pop3.example.com
    user [email protected]
    password your_password
    mda "/usr/bin/procmail -f-"

    Replace pop3.example.com with the POP3 server you want to use, [email protected] with the email address you want to forward from, your_password with your email password, and /usr/bin/procmail -f- with the path to the procmail command.

  3. Save the file and restart the fetchmail service: sudo service fetchmail restart (on Ubuntu-based systems) or sudo service fetchmail restart (on RHEL-based systems).

Remember to replace the placeholders with your actual email addresses and passwords. Also, be aware that mail forwarding may not work if the email account you're forwarding from has two-factor authentication enabled.