[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2018
  • Last Modified:

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.
http://www.experts-exchange.com/OS/Linux/Q_23097900.html#a20751273

Thanks from now!
0
CSecurity
Asked:
CSecurity
  • 11
  • 8
  • 5
2 Solutions
 
GnsCommented:
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
0
 
CSecurityAuthor Commented:
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?
0
 
GnsCommented:
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
0
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
CSecurityAuthor Commented:
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
0
 
GnsCommented:
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
0
 
CSecurityAuthor Commented:
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!
0
 
GnsCommented:
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
0
 
CSecurityAuthor Commented:
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
0
 
GnsCommented:
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
0
 
CSecurityAuthor Commented:
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"

0
 
GnsCommented:
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
0
 
CSecurityAuthor Commented:
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.
0
 
GnsCommented:
Eh.... "mail processor"...?
I think we have a small breakdown in terminology here... In a sense, all the parts you mention would "process" mail, and in that sense be "mail processors";-).

When talking about mail systems one usually talk about the different programs from the viewpoint of "hwat job" they have in the whole process. They are refered to as "Agents" with regard to the job, and sometimes as other things (gateways, hibs etc.... but these are more from a functional and topological viewpoint).
So lets break it down:

Your users interract with a Mail User Agent, typically a webmail application or a more classical mail application like Mozilla ThunderBird or M$ OutLook. The three-letter acronym for these are MUA. A MUA can talk different protocols to different parts of the mail system, for instance SMTP (Simple Mail Transfer Protocol) to send mail, or POP (Post Office Protocol) or IMAP (Internet Message Access Protocol) to retrieve messages from a mail store. A MUA always act as a client in these interractions.

Your mail store is handled by a software that can act as server part in the POP or IMAP interractions. It has to be able to "organize" the mail in the store, and act upon instrucyion from the MUA. It also has to coexist with the MDA (more on that later). This is typically software like Qpopper, CPPop, Dovecot, Cyrus-imap, Courier-imap/pop, M$-Exchange..... All fall into this category (some do a bit more than simple mail store, but there it is:-).

The Mail Transfer Agent is responsible for SMTP service (being the server to MUAs wanting to send messages, acting as both client and server (depending on direction when talking to other MTAs). Into this category falls programs like Exim, Sendmail, Postfix, Zmailer, Qmail, M$-Exchange (yes, that one does it all..... it's a whale... performs like one too:-). The MTA isn't really in chage of the local "transport" from its inbound queue to the actual mail store/mailboxm but it is responsible for kickstarting the Mail Delivery Agent or MDA. The MDA can be as simple as a small script, or as complex as procmail (or worse, in some cases....).

cPanel/WHM use several different softwares to cover these distinct "roles". They seem to prefer Exim for MTA, but can have others, and I'm nor really sure if they use courier-imap (orand/or courier-pop3) to facilitate the actual mailstore... and hide this in cppop, or if cppop is a separate thing (my guess, bordering on absolute certainty:-). Here is a link from @Mail (another "mail server" vendor) about what you need do to replace CPPop with their product: http://kb.atmail.com/?p=374 ... cppop might still just be convenience scripts around courier, but ... there it is:).
If you are using Exim for the MTA bit, then there *should* be a more direct path to get the "always_bcc"-like funtion you want.

Anyway, what we aim at here is to "fork off" a copy of each mail passing through all these different "layers" or "roles" to a separate mail account, without the senders/recipients being none the wiser (apart from the legal stuff you've made them agree to, of course). It can be accomplished at all "levels", but perhaps easiest either at the MTA or the MDA level. Your procmail recipe is just that... it interracts at the MDA level, regardless of how you make procmail be invoked (systemwide or per user).

Easiest would be to do it at the MTA level, and this is what I allude to above, when I talk about roundhouse (the Sendmail way of doing things.... with a mail filter (a.k.a. milter)), always_bcc (the Postfix way....), and that there should be something similar for Exim (I'm not a guru when it comes to Exim, sorry.... Will do a quick Google now...Ah, the Exim FAQ has the answer (item 5033): http://www.exim.org/exim-html-4.30/doc/html/FAQ_19.html#TOC348)

Hope this doesn't muddle the waters for you, but rather clears up what different roles there are to ply in getting email from one point to another, and the possible points at which you can grab a copy.

Cheers
-- Glenn
0
 
slyongCommented:
If I am not wrong CPanel uses Exim which u can use the always_bcc options like what Gns said.

The other way is to use procmail, if your configuration directory is in /etc/procmail, just put into /etc/procmail/rc.localcopy

:0c
! postmaster@mydomain.com # That's exclamation mark, address to forward to.
0
 
CSecurityAuthor Commented:
Thanks a lot, where I should put always_bcc and how I should define it?

Thanks!
0
 
slyongCommented:
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
0
 
slyongCommented:
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.
0
 
CSecurityAuthor Commented:
You was right my server uses exim and it passes mails to mailman. Now what we can do? Thanks
0
 
CSecurityAuthor Commented:
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
0
 
CSecurityAuthor Commented:
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
0
 
slyongCommented:
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

0
 
GnsCommented:
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
0
 
CSecurityAuthor Commented:
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.
0
 
slyongCommented:
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.
0

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

  • 11
  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now