Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a cPanel web hosting account. On this account I have a PHP-based support/trouble ticket system for my customers to use. I'd like to be able to send an email to both my customer and to the ticket system, but have the email that goes to the ticketing system appear to come from my customer, so that the support ticket which gets created appears under their account.

So what I want to do is create some email address billing-redirect@mydomain.com which gets piped to a unix command or shell script. This means that when I send an email from billing@mydomain.com to some_customer@example.com and CC billing-redirect@mydomain.com, the shell script should be able to resend the email to support@mydomain.com but resend the email from the To: address of the email.

Is there any way to make a shell script which will accept an email on stdin, rewrite the From: address, and resend the mail to a new address? Can Procmail do anything like that? Or will I have to hand code this myself?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Procmail comes with the formail command to manipulate mail headers. The procmailex contains examples of uses in .procmailrc. This should do what you want (untested):

formail -R To: From: -U From: -I Cc: -I 'To: support@mydomain.com'
share|improve this answer
    
This is close... it's rewriting the "To:" line but not the "From:". I think it can get me there though! –  Josh May 3 '12 at 12:43
    
@Josh Weird, it works for me: From: billing To: customer Cc: redirect turns into From: customer To: support@mydomain.com. Procmail 3.22 (Debian lenny). –  Gilles May 3 '12 at 22:15
    
Probably a bug in my version of procmail. procmail v3.22 on CentOS release 5.8 –  Josh May 4 '12 at 1:57
add comment

Gilles' answer was almost there, but for some reason I had to pipe through formail twice. In addition, I needed to actually send the mail after rewriting the headers. Here's what I did to make this whole thing work:

  1. I created a new file ~/bin/resend-support containing:

    #!/bin/bash
    
    /usr/bin/formail -R To: From: | \
      /usr/bin/formail -U From: -I Cc: -I 'To: support@mydomain.com' | \
      /usr/sbin/sendmail -oi -t
    
  2. I made the file executable (chmod +x ~/bin/resend-support)

  3. In cPanel, I created an email address forwarder resend-support@mydomain.com which piped to ~/bin/resend-support (using "Pipe to a program" under "Advanced")

Now, when I send an email to someone@example.com and CC resend-support@mydomain.com, it gets piped to ~/bin/resend-support which resends the email to support@mydomain.com from someone@example.com

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.