Operating System - Linux
1825775 Members
2891 Online
109687 Solutions
New Discussion

Re: Forward e-mail to a e-mail account

 
Ng King Wang
Respected Contributor

Forward e-mail to a e-mail account

Hello all,

I would like to do the following thing. Anyone can teach me how to configure it?

When anyone send e-mail, the e-mail will automatically forward to a e-mail account.

Please help :)
We master OpenView, my Lord masters us.
14 REPLIES 14
Nico van Royen
Frequent Advisor

Re: Forward e-mail to a e-mail account

I hope this is what you mean (your question was not that clear..)

Lest say you are on the system as 'john' and the system is called 'system.net' and you want to forward all incoming mail to 'john@system.net' to 'pete@computer.org'.

Telnet to the system.net, change dir to /home/john and create a file called .forward
Inside that file, just put: pete@computer.org
and done.

You can also use the file (if you are superuser) /etc/mail/aliases (or /etc/aliases, depending on your OS).

there you can put lines like:

root: user@some-pc.net
john: who@ever.org

It will accomplish the same.

(if you edit the aliases file, be sure to run the command 'newaliases' to apply any changes made.
If all else fails, try reading the manual...
Ng King Wang
Respected Contributor

Re: Forward e-mail to a e-mail account

Thanks Nico,

Actually, I want to forward all users' outgoing e-mail to a e-mail account.

Let say there are 5 users in my company. All e-mails they send must also forward to the e-mail account of company. How can I do this?

Go ahead :)
We master OpenView, my Lord masters us.
Kurt Beyers.
Honored Contributor

Re: Forward e-mail to a e-mail account

Create a .forward file in every user home directory that contains the email address you want to forward the mail to and restart sendmail.

Kurt
Ng King Wang
Respected Contributor

Re: Forward e-mail to a e-mail account

Hello all,

Let me explain my question one more.

I would like to do the following thing:

When any user send e-mails to anyone, the copy of e-mails will automatically cc to a company e-mail account.

What can I do?

Thanks. :)
We master OpenView, my Lord masters us.
Vincent Fleming
Honored Contributor

Re: Forward e-mail to a e-mail account

It's been a long time since I've done anything like that, but as I recall there is a way to get sendmail to 'cat' the message to a command via the sendmail.cf file. I forget how to write the directive now, but I am very sure that the O'Reilly Nutshell book on Sendmail tells how to do this.

It's a good book to have, even if it is 3 inches thick. ;-)

Good luck!
No matter where you go, there you are.
Felix J. Liu
Advisor

Re: Forward e-mail to a e-mail account

Put 2 lines in every user's .forward file

mail_checker@company.account
/usr/mail/user_login_id

if /usr/mail is where your email is stored.

This will forward a copy of any email to mail_checker and leave a copy in the user's own directory.

However, if the user can modify .forward file then some day you will find your sensorship failed to perform.

In this case sendmail is the thing to play with.

Ng King Wang
Respected Contributor

Re: Forward e-mail to a e-mail account

Hello Felix,

What is the user_login_id???

e.g. the "abc" of abc@company.com

Thanks :)
We master OpenView, my Lord masters us.
Ng King Wang
Respected Contributor

Re: Forward e-mail to a e-mail account

Hello all,

My partner told me that the modification of .forward could not achieve my target. Anyone knows how to configure sendmail.cf for achieving my target. Urgent.

Thanks in advance. :)
We master OpenView, my Lord masters us.

Re: Forward e-mail to a e-mail account

It's probably easiest to write a little script to do this and then edit the /etc/aliases file. Say, we create a script, '/usr/local/bin/mail_dup_and_send'. This script simply copies the message to a local file of your liking and them mails the message off to the intended recipient. However, the script has to accept one argument: a username. Then, in your /etc/aliases file, for every user on your system, create an entry like...

'user: "|/usr/local/bin/mail_dup_and_send user"

Make sure to run newaliases and all should be well. The trick will be the mail_dup_and_send script. I would recommend perl for this.

On a different note, remind yourself of the moral issues involved in what you're doing. Saving email for backup purposes is a good thing. Saving them for some late-night-reading is not a good idea unless it's well-stated in your AUP (acceptable use policy). Just something to think about.

Good luck!
Ng King Wang
Respected Contributor

Re: Forward e-mail to a e-mail account

Thank you,

My partner and I are not familiar with writing Linux script. Can you help us?

Moreover, I also want to know how to edit "sendmail.cf". Anyone can help?

Thanks. :)


We master OpenView, my Lord masters us.
Ng King Wang
Respected Contributor

Re: Forward e-mail to a e-mail account

Hello all,

I forgot to mention one important issue in the previous message.

All e-mails must automatically cc to a company's account.

Please help. :)
We master OpenView, my Lord masters us.

Re: Forward e-mail to a e-mail account

As for the script, you're going to need to pick up a "bash" book and become familiar. After an hour or so of reading, you'll be well on your way.

The sendmail.cf file is historically the most difficult configuration file to take care of. I've only met one person who had a good understanding of it in its post-macro form. Once again, I recommend picking up a book. Oreilly has a good one. If you're going to deal with it a lot, I would recommend understanding the macro (m4) format of the file first. That will at least make you familiar with what sendmail.cf has to offer. I'm not a mail admin. myself, so I can't help you much more in this category. Sorry, and good luck.
CJ Hoeschen
New Member

Re: Forward e-mail to a e-mail account

After reading the replys to this topic most of you are saying to modify the .forward file or the aliases file. This will not work for what he wants to do. The .forwared and aliases file all come into play with e-mail comming to that user, not e-mail going out from that user. The only way I can think of doing this is to modify the sendmail configuration file but I have no idea on how to do it. Don't bother with learning shell scripting or looking into the aliases file. Get yourself a book on sendmail and shave your head because you will want to pull you hair out trying to figure it out :)

Best of luck to you
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein
Penona Chan
New Member

Re: Forward e-mail to a e-mail account

Depending on how your system is configured. But with my system, you simply edit the sendmail.db file and add the email address you are relaying for and then the mail address they want it to be added to.

Example:
joe.bloggs@domain.com joe.bloggs@hotmail.com

Afterwards to just save the file and stop and start the sendmail.

Following commands:

build.aliases
ps -aux (this is to find the code number for the sendmail job)
kill -9 (code number)
sendmail -bd -q15m (this restarts sendmail)

Then hopefully fingers crossed this would include the email address you have added, and where you want to forward it to.


Seek and ye shall find.