Filtering e-mail headers : To,Cc and Bcc

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Filtering e-mail headers : To,Cc and Bcc

Sharma, Ashish-2

Hi,

 

I have a Postfix mail-receiving server.

 

I have to filter the received e-mail according to the logic:

 

1.       Only mails sent to the recipient registered on my email server would be accepted.

2.       Mails sent to the recipient registered on my e-mail server would be rejected if any other recipient of the mail has been specified in To, CC or BCC header.

 

Now I have two options:

 

1.       Write a mail-filter (milter), parse the incoming headers of the mail and implement the logic (I know how to do this).

2.       Using custom postfix feature as listed here: http://www.postfix.org/BUILTIN_FILTER_README.html

  

I have very less idea of option 2,

 

and Will I be able to achieve my intended logic by option 2?

 

If yes please give some good examples.

 

Also, which option would be efficient regarding  performance and memory usage wise?

 

Thanks in advance

 

Ashish Sharma

Reply | Threaded
Open this post in threaded view
|

Re: Filtering e-mail headers : To,Cc and Bcc

Sahil Tandon
On Dec 8, 2009, at 10:14 AM, "Sharma, Ashish" <[hidden email]> wrote:

Hi,

 

I have a Postfix mail-receiving server.

 

I have to filter the received e-mail according to the logic:

 

1.       Only mails sent to the recipient registered on my email server would be accepted.

2.       Mails sent to the recipient registered on my e-mail server would be rejected if any other recipient of the mail has been specified in To, CC or BCC header.

 

Now I have two options:

 

1.       Write a mail-filter (milter), parse the incoming headers of the mail and implement the logic (I know how to do this).

2.       Using custom postfix feature as listed here: http://www.postfix.org/BUILTIN_FILTER_README.html

  

I have very less idea of option 2,

 

and Will I be able to achieve my intended logic by option 2?

 

If yes please give some good examples.

 

Also, which option would be efficient regarding  performance and memory usage wise?

I think you are being overly complex. Read some documentation: postconf(5) is a good start to understand how Postfix rejects mail for everyone except recipients YOU designate as valid.  For the second point, it seems you just need a simple policy service that checks for recipient count and rejects mail if it is > 1.  Also note that there is no BCC header in mail that arrives on your server.
Reply | Threaded
Open this post in threaded view
|

Re: Filtering e-mail headers : To,Cc and Bcc

Terry Carmen
In reply to this post by Sharma, Ashish-2
Sharma, Ashish wrote:

>
> Hi,
>
>  
>
> I have a Postfix mail-receiving server.
>
>  
>
> I have to filter the received e-mail according to the logic:
>
>  
>
> 1.       Only mails sent to the recipient registered on my email
> server would be accepted.
>
> 2.       Mails sent to the recipient registered on my e-mail server
> would be rejected if any other recipient of the mail has been
> specified in To, CC or BCC header.
>
>  
>
> Now I have two options:
>
>  
>
> 1.       Write a mail-filter (milter), parse the incoming headers of
> the mail and implement the logic (I know how to do this).
>
> 2.       Using custom postfix feature as listed here:
> http://www.postfix.org/BUILTIN_FILTER_README.html
>
>  
>
> I have very less idea of option 2,
>
>  
>
> and Will I be able to achieve my intended logic by option 2?
>
>  
>
> If yes please give some good examples.
>
>  
>
You could implement part of what you described with header_checks and a
few regular expressions, however I suspect this won't accomplish what
you want to do, and won't handle bCC in any event, since BCC isn't a
message header.

Messages are delivered based on envelope information, not message
headers. Message headers are completely irrelevant for message delivery.
The recipient information is envelope information, which is transmitted
during the SMTP protocol.

If you really want to only allow single recipient messages, I'd suggest
writing a custom plugin for a mail filter like amavis.

Terry

--
Terry Carmen
CNY Support, LLC
http://cnysupport.com