无法弄清楚如何使用MvcMailer做附件

时间:2012-07-26 17:35:26

标签: asp.net-mvc-3 mvcmailer

究竟如何以及在何处放置字符串attachmentPath的实际文件位置:

public virtual MailMessage Welcome(string attachmentPath)
    {
        var mailMessage = new MailMessage{Subject = "Welcome to MvcMailer"};
        ...
        mailMessage.Attachments.Add(new Attachment(attachmentPath));
        PopulateBody(mailMessage, "Welcome");
        return mailMessage;
    }

c:\inetpub\server\website\docs\test.pdf

的服务器上设定物理文件位置

2 个答案:

答案 0 :(得分:1)

你会做这样的事情:

mailMessage.Attachments.Add(new Attachment((Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\docs\") + attachmentFile))

attachmentFile是您的文件test.pdf

C:\的Inetpub \服务器\网站\文档\检验.pdf

答案 1 :(得分:1)

只需将attachmentPath替换为@“c:\ inetpub \ server \ website \ docs \ test.pdf”,就像这样:

更改attachmentPath

mailMessage.Attachments.Add(new Attachment(attachmentPath));

到@“c:\ inetpub \ server \ website \ docs \ test.pdf”

mailMessage.Attachments.Add(new Attachment(@"c:\inetpub\server\website\docs\test.pdf"));