Adding E-Mail Attachments

Most e-mails contain attachments, so it is important that the SmtpMail object allow for these in some fashion. To create an attachment, the MailAttachment object enables a file attachment to be created; this attachment then can be added to the Ilist collection. The Ilist collection (found in the System.Collections namespace) handles all e-mail attachments.

Attaching a file to an e-mail can be done using one of two methods. First, you can issue a call to the Add() method of the Attachments property. The Add() method takes a single parameter, the pathname to the file. If a MailMessage object were already declared, the following code would be used to make a file attachment.

Visual Basic Example

 MailObj.Attachmenets.Add(new ...

Get Special Edition Using® Microsoft® ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.