MailBee. NET Objects Tutorials

Create and send message with attachment

To attach a file to the message, use the code like below:

C#

Smtp mailer = new Smtp();
mailer.AddAttachment(@"C:\My Documents\Report.xls");

VB.NET

Dim mailer As New Smtp()
mailer.AddAttachment("C:\My Documents\Report.xls")

Smtp.AddAttachment method is in fact the call of Smtp.Message.Attachments.Add method. The developer can use overloads of that Add method to add attachments from other sources (memory array, stream, forwarded e-mail, attachments of specific types, etc). The advanced overloads also allow you to specify the display name of the attachment and other parameters.

For instance, the code below can be used to attach a file named B4DVIS9H.TMP so that it will appear as "Annual report.doc" in the message:

C#

mailer.Message.Attachments.Add(@"C:\DataFiles\B4DVIS9H.TMP", "Annual report.doc");

VB.NET

mailer.Message.Attachments.Add("C:\DataFiles\B4DVIS9H.TMP", "Annual report.doc")