/// <summary> /// Makes debugging emails easier, prevents debug emails from having to actually be sent /// </summary> private void SaveEmailToDisk(EmailMessage email) { string toAddress = email.ToAddresses?.FirstOrDefault()?.Address; try { string emailsFolderPath = _pathProvider.GetAbsoluteEmailsFolderPath(); if (!String.IsNullOrWhiteSpace(emailsFolderPath)) { var info = new DirectoryInfo(emailsFolderPath); if (!info.Exists) { info.Create(); } if (!String.IsNullOrWhiteSpace(email.BodyHtml)) { string htmlFilename = FileUtils.GetFileSafeName(String.Format("{0}-{1}-{2}.html", DateTime.Now.ToString("yyyyMMdd-HHmmss-ffff"), toAddress, email.Subject)); string htmlFilePath = Path.Combine(emailsFolderPath, htmlFilename); File.WriteAllText(htmlFilePath, email.BodyHtml); } if (!String.IsNullOrWhiteSpace(email.BodyText)) { string textFilename = FileUtils.GetFileSafeName(String.Format("{0}-{1}-{2}.txt", DateTime.Now.ToString("yyyyMMdd-HHmmss-ffff"), toAddress, email.Subject)); string textFilePath = Path.Combine(emailsFolderPath, textFilename); File.WriteAllText(textFilePath, email.BodyText); } } } catch (Exception ex) { //This is not a crucial function, don't throw exceptions on error, just log Logger.LogError(ex, "Caught exception saving email To: {0}, Subject: {1}", toAddress, email.Subject); } }