+1 vote
by (160 points)
edited

When sending emails by SMTP you specify [MAIL FROM:] and [RCPT TO:]

I'm doing this just fine using Rebex Secure Mail, and it's working well.

However, the SMTP protocol supports an additional email header of [TO:]. This allows me to send an email to freddy@bigmac.com, but it looks to Freddy like it was sent to freddy@cheeseburger.com.

Why do I want to do this? Well I am downloading email from a POP3 server and sending it on to a different SMTP server. So the POP3 message was originally sent to freddy@bigmac.com, and I am downloading it by pop3 from bigmac.com's pop3 server. I am then sending it to cheeseburger.com's SMTP server. So I have to tell the SMTP server that it's being sent to freddy@cheeseburger.com. But I want Freddy to see that it was originally sent to freddy@bigmac.com.

Sound confusing? Here's how I would do it using telnet:


TELNET mail.cheeseburger.com 25
EHLO
MAIL FROM: peter@applepie.com
RCPT TO: freddy@cheeseburger.com
DATA
TO: freddy@bigmac.com
SUBJECT: Hello Freddy, this is your friend Peter sending you a test email
Hello Freddy, this is the body text
.

In the above example, the email would DEFINITELY be delivered to the mailbox of freddy@cheeseburger.com, but if Freddy was using Outlook then Outlook would show the "TO:" field as being freddy@bigmac.com. Freddy therefore knows which of his email addresses Peter sent his message to.

Sorry, I'm probably not explaining this very well, and it might be sounding way more complicated that it actually is!

I am simply trying to determine how to distinguish between [RCPT TO:] (at the start of the communication) and [TO:] (as part of the DATA section of the communication).

Any help would be appreciated.

Many thanks,

Fork.

Applies to: Rebex Secure Mail

2 Answers

0 votes
by (73.6k points)
edited
 
Best answer

Your question is absolutely clear. This will do the work:

string mailFrom = "peter@applepie.com";
string rcptTo = "freddy@cheeseburger.com";
string mailTo = "freddy@bigmac.com";

Smtp smtp = new Smtp();
smtp.Connect("mail.cheeseburger.com", 25);

MailMessage mail = new MailMessage();
mail.To = mailTo;
mail.Subject = "Hello Freddy, this is your friend Peter sending you a test email";
mail.BodyText = "Hello Freddy, this is the body text";

smtp.Send(mail, mailFrom, rcptTo);
by (160 points)
edited

Brilliant! Thank you both so much - using your examples I was able to do exactly what I wanted. Thanks for showing me how to do this.

Fork.

0 votes
by (148k points)
edited

This can be done easily using Rebex Secure Mail - just use Smtp object's Send(MailMessage mail, string sender, string recipients) method to specify SMTP MAIL FROM and RCTP TO addresses different from those in the message itself. To reproduce the telnet SMTP session above, use the following C# code:

    MailMessage mail = new MailMessage();
    mail.To = "freddy@bigmac.com";
    //mail.From = "peter@applepie.com"; // this was missing from the telnet sample
    mail.Subject = "Hello Freddy, this is your friend Peter sending you a test email";
    mail.BodyText = "Hello Freddy, this is the body text";

    Smtp smtp = new Smtp();
    smtp.Connect("mail.cheeseburger.com", Smtp.DefaultPort);
    smtp.Send(mail, "peter@applepie.com", "freddy@cheeseburger.com");
    smtp.Disconnect();
by (160 points)
edited

Brilliant! Thank you both so much - using your examples I was able to do exactly what I wanted. Thanks for showing me how to do this.

Fork.

...