MvcMailer,查找邮件的文件名

MvcMailer, Find the file name of the email

我正在使用 MvcMailer 将电子邮件保存到我的 asp.net mvc web 应用程序中的本地指定目录。但是我想将电子邮件的文件名(例如 90b871cd-038f-400a-b4d7-01f87e8c3c26.eml)保存在数据库中,稍后将使用另一个 exe 访问该文件名以从拾取文件夹发送电子邮件。

你能告诉我如何从邮件对象中检索文件名吗?

var mail = Mailer.Example_Mail()
mail.To.Add("some@somedomain.com");
mail.Send();

<smtp from="some@somedomain.com" deliveryMethod="SpecifiedPickupDirectory">
    <network host="localhost" />
    <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\" />
</smtp>

提前致谢!

我认为这可能对正在寻找相同问题答案的人有所帮助。我设法克服了编写 System.Net.Mail.MailMessage.Send() 的反射的问题,如下所示。

    public static string SaveToTemp(this MailMessage Message)
    {
        SmtpClient smtp = new SmtpClient();
        string fileName = Guid.NewGuid().ToString() + ".eml";

        string fileNameWithPath = Path.Combine(smtp.PickupDirectoryLocation, fileName);

        Assembly assembly = typeof(SmtpClient).Assembly;
        Type _mailWriterType = assembly.GetType("System.Net.Mail.MailWriter");

        using (FileStream _fileStream = new FileStream(fileNameWithPath, FileMode.Create))
        {
            // Get reflection info for MailWriter contructor
            ConstructorInfo _mailWriterContructor =
                _mailWriterType.GetConstructor(
                    BindingFlags.Instance | BindingFlags.NonPublic,
                    null,
                    new Type[] { typeof(Stream) }, 
                    null);

            // Construct MailWriter object with our FileStream
            object _mailWriter = _mailWriterContructor.Invoke(new object[] { _fileStream });

            // Get reflection info for Send() method on MailMessage
            MethodInfo _sendMethod =
                typeof(MailMessage).GetMethod(
                    "Send",
                    BindingFlags.Instance | BindingFlags.NonPublic);

            // Call method passing in MailWriter
            _sendMethod.Invoke(
                Message,
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new object[] { _mailWriter,true, true },
                null);

            // Finally get reflection info for Close() method on our MailWriter
            MethodInfo _closeMethod =
                _mailWriter.GetType().GetMethod(
                    "Close",
                    BindingFlags.Instance | BindingFlags.NonPublic);

            // Call close method
            _closeMethod.Invoke(
                _mailWriter,
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new object[] { },
                null);
        }
        return fileNameWithPath;
    }     

来电者:

var mail = Mailer.Example_Mail()
mail.To.Add("some@somedomain.com");
var fileName = mail.SaveToTemp(); // Instead of mail.Send();