1

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!

debergalis
  • 11,870
  • 2
  • 49
  • 43
ArielB
  • 1,184
  • 2
  • 11
  • 36

2 Answers2

1

The content of the mail is not parsed by either exchange or the relay for determining where the mail should go. Everyone in this context is talking SMTP with one another, and specify recipients with the RCPT protocol message. So your mail client tells exchange two RCPT, exchange decides one of them is remote, then says one RCPT to the relay, and so on and so forth. This document specifies the SMTP protocol where you may read about the RCPT verb.

Pedro Lamarão
  • 531
  • 5
  • 22
  • does it mean that the relay get him@gmail.com, but the "to" field will contain both mails? – ArielB Nov 25 '12 at 10:44
  • yes, the mail relay or transport agent must not mess with the "To" message header. it is only allowed to add certain headers of it's own, for accounting purposes, as indicated by other commentaries in this question. – Pedro Lamarão Nov 26 '12 at 12:38
0

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • so i understand the "To" field is only for visual representation. does the actual recipient that the sending should occur written somewhere in the message? (if for example, i'm handling EML files - like the iis virtual server) – ArielB Nov 25 '12 at 10:46
  • I'm not sure I understand precisely what you are getting at, but there is indeed no relationship between the `To:` header and the actual recipients (though typically the sender specifies the recipient in the To: and Cc: headers, and the mail submission agent copies those to the envelope; but if the sender has direct control over the envelope, this need not be the case) and there is no guarantee that the envelope recipient is visible in the message itself, although many mail transport agents often include this information in the `Received:` header they add. – tripleee Nov 25 '12 at 15:37
  • The thing is, we are trying to accomplish a mail relay ourselves, and we are using an SMTP listener which saves the requests to disk, then, we are creating new mails and send it. we want to send the mail only to the people who are listed in the RCPT TO and now in the "to" header (as you said, it is not relevant). i wanted to know if it is common to add the RCPT TO inside the message, but you say it doesnt as i understand – ArielB Nov 26 '12 at 08:52
  • That is correct, although as indicated, many receiving MTA:s stamp the RCPT TO: envelope recipient to the `Received:` header it adds. For privacy reasons, this should not be done when there are multiple recipients, though. You will bump into multiple additional questions as you reinvent a wheel which doesn't particularly need to be reinvented. Hope this helps. – tripleee Nov 26 '12 at 09:54