Search code examples
smtpemailrelay

How does a mail relayer doesn't send a mail to already received recipients?


i was wondering.

Suppose i have an exchange server, (the domain can be [email protected]), also, i have a relay server, that accepts requests to internet domains (gmail/yahoo/etc).

suppose i send a mail to: ([email protected]; [email protected]) - from a user in the domain ([email protected])

The mail is sent to the exchange server, then the exchange groups the domains (company.com and gmail.com) => it puts the mail into [email protected] mailbox.

then, the exchange sees that it needs to send into [email protected], so it will send it to the relay server.

the relay server will get the SMTP request:

from: [email protected]

to: [email protected]; [email protected]


the question is - how does the smtp relay server knows not to send it to [email protected] - thus causing duplicate mails received?

also, how does the gmail server knows not to try to send the mails it receives again? (because they only get smtp requests, similar to a client that sends the mail)

thanks in advanced!


Solution

  • The headers you see are not used to deliver the message. Instead, SMTP defines a concept called envelope which has a completely different set of headers. As a common illustration, this is how Bcc: works, too; the recipient address is copied to the envelope, then removed from the message which goes inside the envelope.

    When a message is delivered, the envelope sender is usually copied into the Return-Path: header, and you can sometimes see the envelope recipient information copied into the Received: headers.

    At the point where a mail server decides to which destinations a message should go, there is commonly one copy of the message (spool file, queue entry, what have you) for each distinct destination. So if you send to from you@company to me@company, you@private, and friend@gmail, the first server might determine that the external addresses should both go to the same outbound relay, while the internal copy is delivered locally. Then the relay similarly decides that it needs to contact two distinct destination, so the single incoming message gets copied to two outbound messages, one to you@private and the other to friend@gmail.