究竟如何以及在何处放置字符串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
答案 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"));