0

I use an alias for each company that I provide an e-mail contact. So, for example, in /etc/aliases

somecompany: myuser

The address I supply to SomeCompany would be somecompany@mydomain.com

If the sender's domain is not from somecompany.com, then I can assume it's spam.

Is it possible for sendmail (or another method) to automate checking that the domain matches the alias, else reject the mail?


Following from the answer of @MERM, which suggests the use of procmail, we can create a rule like this: -

:0:
* ^TOsomecompany
* !^FROM.*somecompany.com
/dev/null

It's a good start, but suppressing the delivery is not as effective as the server rejecting it. Is it possible to request that sendmail rejects the mail, rather than simply forward to /dev/null?

  • What you are describing is probably possible, but does it have to be Sendmail? I believe it should be fairly straightforward with Postfix. – tripleee Jan 11 '17 at 15:56
  • @tripleee, the mail server has been running sendmail for over 15 years, so changing would be more problematic and time consuming. – TheDarkKnight Jan 11 '17 at 16:00
  • 1
    Then yeah, you're stuck. There's a saying about Sendmail that you can do anything without invoking an external process, for rapidly decreasing values of "you". – tripleee Jan 11 '17 at 16:06

2 Answers2

1

Are you trying to do this for your account or everyone's account?

You can use procmail to achieve your goal. It is a very powerful filtering tool that will act on rules you create.

Take a look here to get started.

It can be set up for your account or site wide.

MERM
  • 240
  • 2
  • 7
  • Thanks, that's a good start, I would like the mail server to reject the mail and have edited the question accordingly. Any idea if this is possible with procmail, or has the mail officially been accepted by the time procmail receives it? – TheDarkKnight Jan 11 '17 at 15:39
  • 1
    Indeed, by the time Procmail runs, the entire message has already been received by the calling MTA. You can synthesize a bounce message by exiting Procmail with an error, but that simply creates still more traffic, and potentially blowback if the envelope sender was forged. – tripleee Jan 11 '17 at 15:53
  • I think creating such a rule in sendmail would be complex. I switched to 'qmail' long ago which has more straightforward configuration which could do what you want, however I think converting from sendmail to qmail is beyond the scope of what you are looking for. – MERM Jan 11 '17 at 15:55
  • @MERM, indeed, changing the MTA is not really what I'm looking for. I just would have thought this would be something that others may have done already. – TheDarkKnight Jan 11 '17 at 16:02
0

You may use milter e.g. MIMEDefang.

MIMEDefang milter uses perl script for filtering.
It should allow you to reject some RCPT TO: addresses based on MAIL FROM: address.

MIMEDefang package is available in Debian

AnFi
  • 6,103
  • 1
  • 14
  • 27