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:
- Redirecting email to a different account: If you have multiple email accounts, you can forward emails from one account to another.
- 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).
- 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
- Install
procmail
on your Linux system:sudo apt-get install procmail
(on Ubuntu-based systems) orsudo yum install procmail
(on RHEL-based systems). - Create a
.procmailrc
file in your home directory with the following contents::0
- ^To: [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.
- Save the file and restart the
procmail
service:sudo service procmail restart
(on Ubuntu-based systems) orsudo service procmail restart
(on RHEL-based systems).
Method 2: Using the postfix
command
-
Install
postfix
on your Linux system:sudo apt-get install postfix
(on Ubuntu-based systems) orsudo yum install postfix
(on RHEL-based systems). -
Edit the
/etc/postfix/main.cf
file and add the following lines:virtual_alias_maps = hash:/etc/postfix/virtual
-
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. -
Save the file and restart the
postfix
service:sudo service postfix restart
(on Ubuntu-based systems) orsudo service postfix restart
(on RHEL-based systems).
Method 3: Using the fetchmail
command
-
Install
fetchmail
on your Linux system:sudo apt-get install fetchmail
(on Ubuntu-based systems) orsudo yum install fetchmail
(on RHEL-based systems). -
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 theprocmail
command. -
Save the file and restart the
fetchmail
service:sudo service fetchmail restart
(on Ubuntu-based systems) orsudo 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.