1

我究竟如何以及在何处放置字符串的实际文件位置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

4

2 回答 2

1

你会做这样的事情:

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

attachmentFile 是您的文件test.pdf

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

于 2012-07-26T18:47:03.783 回答
1

只需将 attachmentPath 替换为 @"c:\inetpub\server\website\docs\test.pdf" ,如下所示:

更改附件路径

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"));
于 2012-08-18T11:16:38.763 回答