简体   繁体   English

通过C#SMTP发送的电子邮件无法通过电子邮件客户端发送

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

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. 我已经多次将其发送到我自己的邮件地址(我想可能是20封测试邮件),却一无所获。

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. 奇怪的是,公司“ 465”提供的端口并将EnableSsl更改为“ true”,这会使整个应用程序崩溃。

Two questions: 两个问题:

  1. What have I done wrong with SSL? SSL我做错了什么?
  2. How can I make this app show sent emails in the Sent folder? 如何使该应用程序在“已发送”文件夹中显示已发送的电子邮件?

When you're sending via your code, you aren't sending via Microsoft Outlook. 通过代码发送时,不是通过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. 因此,代表用户发送的电子邮件不会显示在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. 除了使用SMTP库发送电子邮件外,您还可以使用某些Exchange(如果您可以控制Web服务器并且实际上是它使用的软件)或使用Outlook SDK来代表用户发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM