Different people mean different things when they say โforward,โ so I think I will give answers to different meanings that I can think of.
1. Forward (Resend) the message without any changes.
In the "No Change" section, I literally do not mean any changes to the data of the raw messages. The way to do this is:
var message = FetchMessageFromImapServer (); using (var client = new SmtpClient ()) { client.Connect ("smtp.example.com", 465, true); client.Authenticate ("username", "password"); var sender = new MailboxAddress ("My Name", " username@example.com "); var recipients = new [] { new MailboxAddress ("John Smith", " john@smith.com ") };
Usually people do not mean this type of โforwardingโ. If they want to resend, usually they will use the following resend method.
2. Forward (resend) the message in the standard way.
var message = FetchMessageFromImapServer (); // clear the Resent-* headers in case this message has already been Resent... message.ResentSender = null; message.ResentFrom.Clear (); message.ResentReplyTo.Clear (); message.ResentTo.Clear (); message.ResentCc.Clear (); message.ResentBcc.Clear (); // now add our own Resent-* headers... message.ResentFrom.Add (new MailboxAddress ("MyName", " username@example.com ")); message.ResentReplyTo.Add (new MailboxAddress ("MyName", " username@example.com ")); message.ResentTo.Add (new MailboxAddress ("John Smith", " john@smith.com ")); message.ResentMessageId = MimeUtils.GenerateMessageId (); message.ResentDate = DateTimeOffset.Now; using (var client = new SmtpClient ()) { client.Connect ("smtp.example.com", 465, true); client.Authenticate ("username", "password"); // The Send() method will use the Resent-From/To/Cc/Bcc headers if // they are present. client.Send (message); client.Disconnect (true); }
3. Forward the message, linking it (in general) with the new message, as some mail clients can do.
var messageToForward = FetchMessageFromImapServer (); // construct a new message var message = new MimeMessage (); message.From.Add (new MailboxAddress ("MyName", " username@example.com ")); message.ReplyTo.Add (new MailboxAddress ("MyName", " username@example.com ")); message.To.Add (new MailboxAddress ("John Smith", " john@smith.com ")); // now to create our body... var builder = new BodyBuilder (); builder.TextBody = "Hey John,\r\n\r\nHere that message I was telling you about...\r\n"; builder.Attachments.Add (new MessagePart { Message = messageToForward }); message.Body = builder.ToMessageBody (); using (var client = new SmtpClient ()) { client.Connect ("smtp.example.com", 465, true); client.Authenticate ("username", "password"); client.Send (message); client.Disconnect (true); }