5

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:
! [email protected]

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?

dexterdev
  • 345
  • 1
  • 2
  • 7

2 Answers2

10

Use :0c for forwarding a copy of a message

:0c
! [email protected]

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.
zuberuber
  • 226
  • 1
  • 7
  • 1
    I use this setup, but i get into problems with DMARC and some domains. I don't know whose fault it is... "550-5.7.1 Unauthenticated email from dhl.de is not accepted due to domain's 550-5.7.1 DMARC policy. Please contact the administrator of dhl.de domain if 550-5.7.1 this was a legitimate mail. Please visit 550-5.7.1 https://support.google.com/mail/answer/2451690 to learn about the 550 5.7.1 DMARC initiative. gk8si37023235wjb.257 - gsmtp" – user56452 Dec 23 '16 at 22:50
  • For loop prevention if you want your gmail to *also* forward to this email: [Procmail sends an extra email](//stackoverflow.com/q/18325261) With this anything to either email ends up in both inboxes. Oops, except you'd need to set up something similar on the gmail side, else everything sent to this address gets bounced to gmail and back (but stops after duplicating). Useful at least a quick hack for me atm. – Peter Cordes Aug 30 '19 at 04:13
0

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: [email protected]" \
    -I"Subject: ${SUBJ_} [autofwd]" \
    | ${SENDMAIL} -f"${FROM_}" [email protected]
}
dexterdev
  • 345
  • 1
  • 2
  • 7
  • 1
    Why would you use a lock file for forwarding email? This is also needlessly complex in a number of ways, but the `X-Loop:` safety measure is a good idea for preventing mail loops. – tripleee Feb 12 '15 at 09:44
  • I got this from http://www.netikka.net/tsneti/info/proctips.php#forward – dexterdev Feb 13 '15 at 10:36