Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29898

Is there any way to Download EML with back date?

$
0
0

I have wrote code for Download EML but i am facing one issue:

While downloading EML i am getting date time as current date time, i need this to be back dated.

Is there any options available?

I need the email time not the download time, any help is appreciated

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);
                }

Viewing all articles
Browse latest Browse all 29898

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>