Forwarding my institute mail to gmail?

I wanted to forward emails which comes to my institute mail to my gmail, while keeping the originals in the institute account too. I tried editing my /.procmail file like below:

# Forward everything to me at gmail
:0:
! myusername@gmail.com

This was working fine except the original mail is just bouncing to gmail account, not getting stored at institute mail account. What to do for this?

Asked By: dexterdev

||

I got a method from this link. But I dont know if it has any pitfalls.

SENDMAIL=/usr/sbin/sendmail
FROM_=`formail -c -I"Reply-To:" -rt -xTo: 
  | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
SUBJ_=`formail -xSubject: 
       | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`

# Make a copy of all email to my second address
:0
* ! ^X-Loop: myid@myhost.mydom
{
  :0c:${HOME}/procmail.lock
  | formail -A"X-Loop: myname@institute.domain" 
    -I"Subject: ${SUBJ_} [autofwd]" 
    | ${SENDMAIL} -f"${FROM_}" myusername@gmail.com
}
Answered By: dexterdev

Use :0c for forwarding a copy of a message

:0c
! myusername@gmail.com

c flag documentation:

c    Generate  a  carbon  copy  of this mail.  This only makes sense on delivering recipes.  The only
        non-delivering recipe this flag has an effect on is on a nesting block, in order to  generate  a
        carbon  copy  this  will  clone  the running procmail process (lockfiles will not be inherited),
        whereby the clone will proceed as usual and the parent will jump across the block.
Answered By: zuberuber
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.