Есть ли способ скачать EML с задним числом? - PullRequest
0 голосов
/ 28 февраля 2020

Я написал код для загрузки EML, но столкнулся с одной проблемой:

При загрузке EML я получаю дату и время в качестве текущей даты, мне нужно, чтобы это было датой назад.

Есть ли варианты?

Мне нужно время электронной почты, а не время загрузки, любая помощь приветствуется

enter image description here

using (var client = new SmtpClient())
                {
                    MailMessage msg = new MailMessage(from, to, subject,body);
                    if(!string.IsNullOrEmpty(cc))
                        msg.CC.Add(cc);

                    if(email_attachments.Count > 0)
                    {
                        for(int i = 0; i < email_attachments.Count; i++)
                        {
                            msg.Attachments.Add(new Attachment(Server.MapPath(string.Format(ConfigurationManager.AppSettings["SaveAttachment"].ToString(), "Deployment-" + Convert.ToString(Session["DeploymentID"]), "Ticket"))
+ email_attachments[i]));
                        }
                    }
                    msg.IsBodyHtml = true;


                    client.UseDefaultCredentials = false;

                    client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    client.PickupDirectoryLocation = emailDir;

                    try
                    { 
                        //msg.Headers.Add("Date", DateTime.Now.AddDays(-2).ToString("ddd dd-MM-yyyy hh:mm tt"));
                        client.Send(msg);
                        logger.Log(LogLevel.Info, "Email Saved as EML");
                    }
                    catch (Exception ex)
                    {
                        Environment.Exit(-1);
                    }
                }

                var defaultMsgPath = new
                   DirectoryInfo(emailDir).GetFiles()
                      .OrderByDescending(f => f.LastWriteTime)
                      .First();
                var realMsgPath = Path.Combine(emailDir, msgName);


                try
                {
                    System.IO.File.Move(defaultMsgPath.FullName, realMsgPath);
                    logger.Log(LogLevel.Info, "Email Saved as EML and Moved to directory with new file name");
                }
                catch (System.IO.IOException ex)
                {
                    System.IO.File.Delete(realMsgPath);
                    System.IO.File.Move(defaultMsgPath.FullName, realMsgPath);
                }
...