MailBee. NET Objects Tutorials

Adding multiple attachments

MailBee.NET Objects library allows you to manage the collection of Attachment objects which represents all attachments of the mail message. You can access this collection through SMTP.Message.Attachments property of the SMTP object. To add multiple attachments to the message, make a call of SMTP.Message.Attachments.Add method or its overloads for every attachment. The different overloads of this method let you 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:

C#

oMailer.Message.Attachments.Add(@"C:\Temp\report.doc");
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);

VB.NET

oMailer.Message.Attachments.Add("C:\Temp\report.doc")
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 above example adds four attachments to the message. The first document is attached as "report.doc". The second document is attached as "prs2005.xls". The third attachment is a picture, with its own CID (you could refer it as <IMG SRC="cid:12s4a8a8778c$5664i1b1$ir671781@tlffmdqjobxj"/> within the HTML message body). And the last attachment is forced as an inline object (in mail clients it's rendered with the message body rather than shown in the attachments list).