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.
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"
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:
using Rebex.Mail; using Rebex.Net; using Rebex.Mime.Headers; ... // 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 Smtp.Send(message, "smtpserver.example.com");
'Imports Rebex.Mail Imports Rebex.Net Imports Rebex.Mime.Headers ... ' 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 Smtp.Send(message, "smtpserver.example.com")