LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Forwarding messages to another server via procmail (https://www.linuxquestions.org/questions/linux-software-2/forwarding-messages-to-another-server-via-procmail-279090/)

handsomeRob 01-17-2005 08:45 PM

Forwarding messages to another server via procmail
 
Hello,

I'm trying to forward some messages to Server A and the rest to Server B. I basically have a text file of email addresses. I then grep it in procmail and see if intended recipient is in my list. If it is, the message is sent to Server A. If not, it's sent to Server B.

I read the procmail FAQ but all I get was solutions on how to forward messages per user. I want to filter each and every message that comes in and forward it to the right server. I'm thinking the global /etc/procmailrc should do the trick. But how do I forward the message to another server? AFAIK, you can only forward a message to another email address or a folder. Or can I pipe it to another program and have that program foward messages to another server?

If this is not possinble in procmail, any suggestions for alternatives solutions?

jgombos 01-17-2005 11:40 PM

I don't get it. When you forward to another email address, you are in fact forwarding it by way of server. Procmail just hands it off to sendmail, which then does the work of DNS queries to find he correct MX server, and it connects to that MX server and sends the message.

So if you are running serverB and want to forward a message to serverA for Bob, your script would look something like:

:0
* ^TO_bob@serverB.com
! bob@serverA.com

handsomeRob 01-18-2005 02:27 AM

Sorry, I wasn't clear enough. Here's the scenario:

Our company has decided to ditch our email services. The problem is, the customers and ourselves have the same domain, say foobar.com.

A company offered to host our customers on their end and host their emails (Server B). But we still want to retain the domain and only have the mails of the customers go to Server B if the message is not for us. If the message is for us, the message is sent to Server B.

We have a server from another location. I will change the MX of record of foobar.com and point it there thereby accepting emails for foobar.com.

So here's what I want to do:

1. Message arrives
2. Recipient check. Is it for us?
Yes. Send message to server A
No. Send message to server B

I can't just make .procmailrc entries for each user since I'd have to add these users to the system.

jgombos 01-18-2005 12:32 PM

Procmail only supports these actions:
[list=1][*]Deliver to an Mbox[*]Deliver to a Maildir[*]Forward to an email address[*]Deliver to a program[/list=1]

I don't know much about DNS, but it seems if your clients are running their own mailserver, you should be able to forward messages to internal email addresses, which would mean creating an internal MX record somehow, so you could forward bob@foobar.com to bob@serverb.foobar.com. Is it possible to have an MX lookup on serverb.foobar.com return something different than an MX lookup on foobar.com?

Also, why would Server A be required in your case? If the mail is for "us", then deliver the message directly in the users mail spool.

If DNS cannot be setup to accommodate the other server, I think your only option is to deliver to a program using a pipe. You can probably have an action like:

| sendmail <all switches needed to deliver to specific server>

BTW- you would probably get a better answer on the procmail mailing list. Chances are, someone there has had to do this.

handsomeRob 01-18-2005 06:38 PM

jgombos,

Thanks for your input. Our clients are just end-users with email-clients (eudora, outlook, etc). The reason for sending our message to server A is that the MX server will be located somewhere else from another network. We don't want our network to accept emails not for us (at least not in our list).

We want to transition to be as seamless as possible.

Thanks for the procmail tips. I guess my option is to pipe the mail to sendmail or another program.

Thanks.

handsomeRob 01-18-2005 07:08 PM

I found the answer! Thanks jgombos for the help. The solution isn't procmail and I hope this will be useful to someone someday.

The answer is sendmail's virtusertable. Since I already have a list of email addresses that I want to re-route to Server A, I can simply do this:

In the first 3 lines, emails will be sent to serverA. The rest of the emails with @foobar.com will be sent to ServerB. The %1 is a map for whatever username the @foobar.com is.

More of it can be found here:
http://www.sendmail.org/virtual-hosting.html


All times are GMT -5. The time now is 11:06 AM.