1

Exactly how, and where, do I place the actual file location for the string 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;
    }

Presume a physical file location on the server of c:\inetpub\server\website\docs\test.pdf

REMESQ
  • 1,190
  • 2
  • 26
  • 60

2 Answers2

1

You would do something like this:

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

Where attachmentFile is your file test.pdf.

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

Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
  • Sorry for the late response. Where exactly am I "declaring" (if that's what it is) `attachmentFile`? And how do I "declare" it? – REMESQ Jul 29 '12 at 14:57
1

Just replace attachmentPath with @"c:\inetpub\server\website\docs\test.pdf" like this:

Change attachmentPath

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

to @"c:\inetpub\server\website\docs\test.pdf"

mailMessage.Attachments.Add(new Attachment(@"c:\inetpub\server\website\docs\test.pdf"));
Kelvin Lai
  • 2,209
  • 7
  • 24
  • 26