0

I'm doing a WebForm where the user can forward a selected e-mail. This is the method I'm using:

public bool SendEmail()
        {
            SmtpClient smtpServer = new SmtpClient("host");

            try
            {
                smtpServer.Port = port;
                smtpServer.Credentials = new NetworkCredential("user", "pass");
                smtpServer.EnableSsl = false;
                MailMessage msg = new MailMessage();
                msg.To.Add(txtTo.Text);
                msg.From = new MailAddress("address");
                msg.IsBodyHtml = true;
                msg.Subject = "FW: " + txtSubject.Text;
                msg.Body = txtBody.Value;

                //Sending email
                smtpServer.Send(msg);
                smtpServer.Dispose();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

It's working just fine, but the thing is that this is basically copying the e-mail and sending to the address informed by the user. Is there a way to just forward the message, instead of copy and send a new one, using SmtpClient?

Liam
  • 27,717
  • 28
  • 128
  • 190
Wanderer
  • 7
  • 3
  • Is this useful? https://www.limilabs.com/blog/forward-email – Muzaffer Galata Nov 30 '20 at 16:45
  • It is not very clear what you are asking. Where is the duplication happening? – WiseGuy Nov 30 '20 at 17:02
  • SMTP is only for sending emails. You would need to connect to an application that reads an email account and then forward. – jdweng Nov 30 '20 at 17:19
  • @jdweng ouch, that's sad. Thank you for the comment, man. – Wanderer Nov 30 '20 at 18:19
  • @WiseGuy Actually there's no duplication. The thing is that I get the message selected by the user, copy the subject and body contents from it and send it to the address informed by the user. It's like a "fake forward", you know? Because I'm sending a new e-mail with the same contents of the other, not actually forwarding the original one. – Wanderer Nov 30 '20 at 18:37
  • @MuzafferGalata thanks for the reply man. I think I'll have to change the way I'm doing to something like this you've sent. I think I'll look for some library on GitHub to do this. – Wanderer Nov 30 '20 at 18:40
  • You may find this helpful: https://stackoverflow.com/questions/29414995/forward-email-using-mailkit-c/29447087#29447087 – jstedfast Dec 02 '20 at 14:23

0 Answers0