Adding an email attachment in .Net
I wanted to add an email attachment to a mail message that I was sending (when coding in ASP.Net). This tripped my up for a bit, but it turns out to be really easy. Turns out there is a method to do this on the MailMessage object. Here's how it's done:
-- Start by setting up your mail object. Yours may be different, but here's an example:
-- All that's needed to include the attachment is a call like this:
-- Start by setting up your mail object. Yours may be different, but here's an example:
Dim objEmail as New MailMessage objEmail.To = "someone@somecompany.com" objEmail.FROM = "me@someothercompany.com" objEmail.BODY = "some message" etc, etc, etc
-- All that's needed to include the attachment is a call like this:
objEmail.Attachments.Add(new MailAttachment(server.MapPath("/path/to/myfile.txt")))| Rating: | 0% positive, 1 Vote |
| Categories: | programming ASP .Net web |
| Added: | on Apr 26, 2007 at 3:49 pm |
| Added By: | an anonymous user |

