MailBee. NET Objects Tutorials

Adding multiple attachments

MailBee.NET Objects allow the developer to manage the collection of Attachment objects representing all attachments of this mail message. This collection is accessible through the SMTP.Message.Attachments property of the SMTP object. To add multiple attachments to the message, the developer should iterate calling the SMTP.Message.Attachments.Add method. The different overloads of this method allow the developer to specify not only the path to the file which should be attached, but also the other parameters, such as Content-ID (CID), target file name, Content-Type, etc:


oMailer.Message.Attachments.Add(@"C:\Temp\prices_2005.xls", "prs2005.xls");
oMailer.Message.Attachments.Add(@"C:\Temp\my_photo.jpg", "pic1.jpg","<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>");

oMailer.Message.Attachments.Add(@"C:\Temp\john_doe_photo.jpg", "pic2.jpg","<12s4a8a8932r$5664i1t1$iy671661@yljfmkqjghxu>", "image/gif", null, NewAttachmentOptions.Inline,  MailTransferEncoding.Base64);


oMailer.Message.Attachments.Add("C:\Temp\prices_2005.xls", "prs2005.xls")
oMailer.Message.Attachments.Add("C:\Temp\my_photo.jpg", "pic1.jpg","<12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj>")
oMailer.Message.Attachments.Add("C:\Temp\john_doe_photo.jpg", "pic2.jpg", "<12s4a8a8932r$5664i1t1$iy671661@yljfmkqjghxu>", "image/gif", Nothing, NewAttachmentOptions.Inline, MailTransferEncoding.Base64)

The example above adds four attachments to the message. The first document is attached as report.doc. The second document is attached as prs2005.xls with the specified CID. The third attachment is a picture, also having its own CID. And the last attachment is forced as inline object in Base64 encoding.

In case the attachment is considered to be an inline object it is displayed along with the message body. However, if the developer needs to refer to this attachment anywhere from the message body, the corresponding CID should be assigned to this attachment.