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 me@company.com), also, i have a relay server, that accepts requests to internet domains (gmail/yahoo/etc).

suppose i send a mail to: (you@company.com; him@gmail.com) - from a user in the domain (me@company.com)

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

then, the exchange sees that it needs to send into him@gmail.com, so it will send it to the relay server.

the relay server will get the SMTP request:

from: me@company.com

to: you@company.com; him@gmail.com


the question is - how does the smtp relay server knows not to send it to you@company.com - 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.