Link to home
Start Free TrialLog in
Avatar of CSecurity
CSecurityFlag for Iran, Islamic Republic of

asked on

CPPOP (Cpanel Mail Server) Send a copy of incoming mails

Hello

I have a Linux OS which have a Cpanel pop3 server installed and it works well.

I have a mail account in it like info@mysite.com

Now, I want to have a copy of each mail I receive in this mail account to be forwarded or sent to another account I have in Yahoo. How can I do that?

I want original mail to be stored in server, just I want to have a copy of received mails in another mail account.

Another person solved my problem in another type of POP3 server (QPopper), now I want same for Cpanel POP3 server.
https://www.experts-exchange.com/questions/23097900/Qpopper-POP3-send-a-copy-of-received-mails-to-another-mail.html?anchorAnswerId=20751273#a20751273

Thanks from now!
Avatar of Gns
Gns

Hmmm. CPPOP or Qpopper doesn't really matter, since what you've been using likely affects aither the ;ail Transfer Agent (Sendmail, Postfix, Exim ... whatever....) or the MailDelivery Agent (some MTAs pass off to procmail fro that). That you use CPanel does make things more ... complex, in a way...

Easiest "solution" is to have an alias that "fork off" a separate message to the second address... Something like:
info realinfo, youraddress@yahoo.com
... in an appropriate alias file (this is where CPanel is more complex:-)... See if the panel don't have an appropriate setup applet for that....
Else you need look at what MDA is used and use a method appropriate to that (a procmail recipe, a fun .forward or ... something similar).
Pretty much as you did in the other question,

-- Glenn
Avatar of CSecurity

ASKER

Thanks for your help
.forward will forward orginal mail, will not send copy, how can I understand what my server uses to process mails, procmail or anything other?
I must warn you that I do not use CPanel myself, but have come into contact with it on numerous occasions (through my engagement in the MailScanner community (an AV and spam handling app for numerous sizes,  complexities and implementations (MTAs, AVs etc)). From what I remember of that I'd say that you likely use Sendmail (in a CPanelized dashion:-), but might be using Postfix (or even Exim)... And likely don't have procmail as MDA... Might not mean you can't use it though:-).
If you can run a simple ps/grep, something like:
ps auxww|egrep "sendmail|exim|qmgr"
might at least tell you what MTA is in play (qmgr is one of the essential Postfix processes that just have to be there to be running Postfix... The other two are monolithic (meaning "one program to do it all").

You jhave to understand another thing about email.... There is no huge difference between any of the methods in regard to whether a message sent to your other address would be a copy or not.
There migt be some differences in the Received: lines in the header, but that's about it.
I didn't look to hard at the procmail recipe... Was that a kind of "send message as an attahment" thing? If not, then the difference of methods are purely cosmetic.

Cheers
-- Glenn
Hello thanks for your help.

procmailrc method in other question worked very well without problem, it seems I want same thing for sendmail, I think server uses Sendmail in this server. No problem about AV etc. :)

Thanks
Well then, if the server isn't setup to do procmail for all users, you sure can do it yourself, for that one user/address, provided procmail is installed. To determine if it is, do
procmail -v
on a commandline prompt. If it spews a bit of info on what version is installed, you then do:
which procmail
to determine where it is installed (you need this information below...)... Then you can safely move ahead to the next step, which is to use your users .forward file to call procmail.... (see, this is one of the "fun" things you can do with your .forward file:-)...
Your forward file should look like:
"|IFS=' '&&p=/usr/bin/procmail&&test -f $p&&exec $p -Yf-||exit 75 #YOUR_USERNAME"
where you replace (if necessary) the part saying /usr/bin/procmail with whatever "which procmail" returned.
The .forward file needs be "readable by all", so do
chmod 0644 .forward
and you should be done (with this part).

Then create your .procmailrc file exactly as in the previous question, and you relax, kick back and enjoy:-).

A lot of "ifs'n'buts", don't be shy asking if something doesn't work out.

Cheers
-- Glenn
Thanks for your help. But for now mailing and all works, but I can't see any .forward in any user's directory.

I mean in /home/USERNAME1/.forward doesn't exists.

So what processor currently have been set? Now if I add .forward file with line you said for all users in their home directory it will not disturb current working app?

Thanks once again!
1) It will be completely harmless for the users that lack a .procmailrc file to go with the .forward file. Mail will be completely undisturbed for them.
2) For those users that need something like this, you need create a .procmailrc file with a working recipe, like the one in the other question.
3) If in doubt, simply don't add the .forward to users that don't need the .procmailrc file.

(I know this from experience;-)...

-- Glenn
So now, you are suggesting me to add .forward or .procmailrc for each users? I added procmailrc in etc but it not worked, now how you say if I add .forward file for each user it will work?

And some more info to clarify my need:

1) I want anymail@mysitesinmyserver.com to be forwarded (orginal will remain, I want a copy) in another mail.

2) If possible I want a general policy or config file, so I'll get ALL@ALLSITESINMYSERVER.com mails.

Really Thanks for your help
Ah, with that need, you could've gone the roundhouse (sendmail milter) way instead, or (if you had used postfix) the always_bcc option... or if you install/run MailScanner (you'll probably need the configserver one, not the plain vanilla) you could've used the Archive Mail feature .... Isn't it fun when there are so many ways to do what one wants:-).
The /etc/procmailrc thing you've used before should work with the .forward file as well. Try it again, with a user where you add the specific "procfile enabling" .froward file.
Best would be to "enhance" sendmail with procmail support (You haven't seen anything in the CPanel interface about enabling this? I sure STR something like that...hmmm..), but CPanel usually do things a bit differently from "normal" when it comes to server process configuration, so ... I dare not fits with that...:-).
The .forward should be safe though. Make it read-only and owned by root (or nobody) so that the users can't change it on a whim.
Best would though be to get this to work from the MTA (Sendmail isn't a given with CPanle, it might be Exim, in which case you should read this: http://www.webhostingtalk.com/archive/index.php/t-46621.html ... seems .... ot that nice...).
I'll snoop around a bit and see what turns up.

-- Glenn
What should I put instead of YOUR_USERNAME in this:
"|IFS=' '&&p=/usr/bin/procmail&&test -f $p&&exec $p -Yf-||exit 75 #YOUR_USERNAME"

Nothing.... It should litteraly say YOUR_USERNAME ... or anything you like...:-). Could be good to use the actual users login name there, to differentiate when looking at process listings:-). But I usually leave it as is, since it is there to work around some over-optimistic implementations of SendMail (well...)... Procmail will never see it (due to the hash (#) comment sign, that part will be stripped).
If you were to be running Exim, that part could potentially land you in trouble... as shown on the page I refered to.
But by now I suppose you've determined that you are indeed running sendmail...? So that wouldn't be a problem... Right?

Cheers
-- Glenn
How can I understand what my POP3 server is and which mail processor parses incoming mails? ALL softwares like procmailrc, CPPOP, SendMail etc. etc. installed. I want to know what is my POP3 server, where it is and what is my mail processor.
ASKER CERTIFIED SOLUTION
Avatar of Gns
Gns

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot, where I should put always_bcc and how I should define it?

Thanks!
hmm... Sorry CSecurity, it seems like Both Gns and I was wrong about exim.  That option in exim is different from postfix.  In postfix, you can have always_bcc someone@somewhere.com to forward all mails.  In exim, it only insert a blank bcc header to comply with the standard.

I am not a guru in exim either, I found that to use procmail for exim, you need to edit the exim.conf file as in http://www.exim.org/exim-html-current/doc/html/spec_html/ch29.html#SECID143.

Then you can use the procmail recipe
Hi CSecurity, take a look at this http://www.devco.net/archives/2006/03/24/saving_copies_of_all_email_using_exim.php and see if you can digest it.  If not drop a message and I will go through it with you.
You was right my server uses exim and it passes mails to mailman. Now what we can do? Thanks
Look at here:


mailman_virtual_transport_nodns:
    driver = pipe
    command = /usr/local/cpanel/3rdparty/mailman/mail/mailman \
              '${if def:local_part_suffix \
                    {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
                    {post}}' \
              ${lc:$local_part}


A part of exim.conf file
I think we can add always_bcc to mailman parameters, a quick question, if we add always_bcc, all incoming mails will be edited? So in normal inbox, there will be bcc and will show my mail address or no? Thanks for your help
Hi, always_bcc will not work.  Refer to http://www.devco.net/archives/2006/03/24/saving_copies_of_all_email_using_exim.php on how to do a copy of mail.

1) To get a copy of outgoing mail, create the directory /var/mail/domain.com/mailarchive first then edit the file "/etc/cpanel_exim_system_filter" and add:
unseen save /var/mail/domain.com/mailarchive/.${tr{$sender_address}{.}{_}}.outgoing/

2) To get a copy of incoming mail, use shadow_transport.  In your /etc/exim.conf, search for address_directory and change it to:
address_directory:
  driver = appendfile
  create_directory
  delivery_date_add
  directory_mode = 770
  envelope_to_add
  maildir_format
  return_path_add
  shadow_transport = local_copy_incoming
  shadow_condition = ${if eq {$domain}{domain.com}{yes}{no}}

local_copy_incoming:
  driver = appendfile
  directory = /var/mail/domain.com/mailarchive/ \
      .${tr {$local_part}{.}{_}}@${tr {$domain}{.}{_}}.incoming/
  delivery_date_add
  envelope_to_add
  return_path_add
  group = exim
  user = exim
  mode = 0660
  maildir_format = true
  create_directory = true

Man, you'vebeen busy.... A couple of days with the flu (on my part), and you've found all that:-)
Good info the slyong, thanks for chipping in!

-- Glenn
Thanks slyong, I want to copy incoming mails, I added your changes, but I should define a mail address so each incoming mails will be sent to another mail? Thanks a lot for your help.
You mail will be replicated in

   directory = /var/mail/domain.com/mailarchive/ \
      .${tr {$local_part}{.}{_}}@${tr {$domain}{.}{_}}.incoming/

maildir, match it against your user and you will get the mail into the user's account.