0

请我有一个工作代码,只有当我从 Visual Studio 执行应用程序时才能正确发送邮件,但是当我生成 .exe 文件并安装它时,我无法收到电子邮件!我认为这不是来自代码的问题,但也许是其他问题。
使用 NReco.Generator 生成并附加到每封邮件的 PDF 文件(这不是访问问题,因为我可以毫无问题地将相同的文件发送到 Box)。
可能是什么问题?在 Visual Studio 中一切正常,但在安装后就不行了!
这是生成和发送文件的代码:

  void EnvoyerDOCAsync(string path)
    {

        SmtpClient MyMail = new SmtpClient(ConfigurationManager.AppSettings["server"], Convert.ToInt16(ConfigurationManager.AppSettings["port"]));
        MyMsg = new MailMessage();

        MyMsg.Priority = MailPriority.High;
        MyMsg.From = new MailAddress(ConfigurationManager.AppSettings["mail"], "Sesrvice Mailing");

        foreach (Fonction item in fonction.getFonctions())
        {
            MyMsg.To.Add(new MailAddress(item.FonctionMail, item.FonctionName));
        }

       MyMsg.Subject = "Hello";
        MyMsg.Body    = "Bonjour";
        MyMsg.SubjectEncoding = Encoding.UTF8;
        MyMsg.IsBodyHtml = true;
        MyMsg.BodyEncoding = Encoding.UTF8;
        MyMail.UseDefaultCredentials = false;
        MyMail.Timeout = (60 * 5 * 1000);
        NetworkCredential MyCredentials = new NetworkCredential(ConfigurationManager.AppSettings["sso"], ConfigurationManager.AppSettings["pass"]);
        MyMail.Credentials = MyCredentials;


        if (File.Exists(path))
        {
            if (path != null)
            {
                    Attachment attachment = new Attachment(path, MediaTypeNames.Application.Octet);

                    System.Net.Mime.ContentDisposition disposition = attachment.ContentDisposition;
                    disposition.CreationDate = File.GetCreationTime(path);
                    disposition.ModificationDate = File.GetLastWriteTime(path);
                    disposition.ReadDate = File.GetLastAccessTime(path);
                    disposition.FileName = Path.GetFileName(path);
                    disposition.Size = new FileInfo(path).Length;
                    disposition.DispositionType = DispositionTypeNames.Attachment;

                    MyMsg.Attachments.Add(attachment);
                    MyMail.SendAsync(MyMsg, null);
                    MyMail.SendCompleted += MyMail_SendCompleted;
            }
        }

    }



//Execute this after mail is sended to dispose the Msg and show validation message.<br/>
  private void MyMail_SendCompleted(object sender, AsyncCompletedEventArgs e)
    {

        MyMsg.Dispose();

       MessageBox.Show("The mail was sended succesfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }


谢谢你。

4

0 回答 0