Many mail agents including Outlook support sending email from one user on behalf of another one. When you reply to such message, the response is sent to the user on whose behalf the message it was sent. One of the usage scenarios is a support group where emails are sent by each member on behalf of the whole group. A reply to any such e-mail is therefore sent to the group.
Microsoft Outlook displays the sender of such email as "email@example.com of behalf on firstname.lastname@example.org".
Can this be achieved with Rebex Mail for .NET?
Yes, this is easily possible using the MailMessage class – just you use the code from this tutorial and add the following line:
message.Sender = "email@example.com"
The resulting e-mail from field will appear as "firstname.lastname@example.org of behalf on email@example.com"
Also worth noting is that the From property (and field) can contain multiple e-mail originators, while the Sender property (and field) can only contain either one address or none. Also, when the From is set to multiple originators, the Sender should be set as well. For detailed information about From, Sender and also Reply-To field, consult section 3.6.2 of RFC 2822.
Complete source code follows:
// create an instance of MailMessage
MailMessage message = new MailMessage();
// and set its properties to desired values
message.From = "firstname.lastname@example.org";
message.Sender = "email@example.com";
message.To = "firstname.lastname@example.org";
message.Subject = "This is a simple message";
message.BodyText = "Hello, Joe!";
// send the message
' create an instance of MailMessage
Dim message As New MailMessage
' and set its properties to desired values
message.From = new MailAddressCollection("email@example.com")
message.Sender = new MailAddress("firstname.lastname@example.org")
message.To = new MailAddressCollection("email@example.com")
message.Subject = "This is a simple message"
message.BodyText = "Hello, Joe!"
' send the message
This sample applies to the following components: Rebex Mail for .NET, Rebex Secure Mail for .NET, Rebex Total Pack