Emails sent via C# SMTP are not seen through email client as sent

980 Views Asked by At

If I try to send emails such as easy "newsletter", none of them appears as sent in my "Sent" folder. I've sent it to my own mail addresses multiple times (I would say it could be 20 test mails) and nothing.

Can you advise me how to do it?

This is the code of the application:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        // passwordBox.PasswordChar = '*';
    }

    private void sendButton_Click(object sender, EventArgs e)
    {
        string receiver = toBox.Text;
        char[] spl = new char[2] { ';', ',' };
        string[] receivers = receiver.Split(spl);

        //mail details
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress("xxx@xxx");
        mail.Subject = topicBox.Text;
        mail.Body = contentBox.Text;

        //smtp details
        SmtpClient SmtpServer = new SmtpClient();
        SmtpServer.Host = "mail.xxx";
        SmtpServer.Port = 25;
        SmtpServer.Credentials = new NetworkCredential("xxx@xxx", "password");
        SmtpServer.EnableSsl = false;

        for (int i = 0; i < receivers.Length; i++)
        {
            try
            {
                mail.To.Add(receivers[i].ToString());

                SmtpServer.Send(mail);

                MessageBox.Show("Mail for " + mail.To.ToString() + " send!", " Success!", MessageBoxButtons.OK);
                mail.To.RemoveAt(0);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString() , "Error");
                return;
            }
        }
    }
}

Strange thing, the port which is provided by a company "465" and change EnableSsl to "true" keep crashing whole app.

Two questions:

  1. What have I done wrong with SSL?
  2. How can I make this app show sent emails in the Sent folder?
1

There are 1 best solutions below

0
On

When you're sending via your code, you aren't sending via Microsoft Outlook. You're sending it directly to the server. So emails sent on a user's behalf won't show up in their sent folder in Outlook. The email will only be seen by the people that receive the email (To, CC, and BCC).

Instead of using the SMTP libraries to send the email, you could use some Exchange (if you have control over the web server and that is in fact the software it's using) or Outlook SDK's to send on the user's behalf.