Reads the specified file from disk and adds it as attachment to the message.
true if the method succeeds; otherwise, false.
Smtp.AddAttachment method is equivalent to Smtp.Message.Attachments.Add method (see Add).
The developer can use overloads of Add method to add attachments in an advanced way (memory or stream attachments, attachments of a specific type, etc).
Note If you send multiple messages reusing the same Message object, be sure to clear Attachments collection of Message object by calling Clear method after each send. Otherwise, the attachments added to the collection during send operation will still remain in the collection when new attachments are added for the next send operation.
| Exception Type | Condition |
|---|---|
| MailBeeException | An error occurred and ThrowExceptions is true. |
Adding an attachment to the message using Smtp.AddAttachment and Smtp.Message.Attachments.Add methods.
[C#] // To use the code below, import MailBee namespaces at the top of your code. using MailBee; using MailBee.SmtpMail; // The actual code (put it into a method of your class) Smtp mailer = new Smtp(); // Add attachment under real name. mailer.AddAttachment(@"C:\My Documents\Report.xls"); // Add B4DVIS9H.TMP file as "Annual report.doc". mailer.Message.Attachments.Add(@"C:\DataFiles\B4DVIS9H.TMP", "Annual report.doc");
[Visual Basic] ' To use the code below, import MailBee namespaces at the top of your code. Imports MailBee Imports MailBee.SmtpMail ' The actual code (put it into a method of your class) Dim mailer As New Smtp ' Add attachment under real name. mailer.AddAttachment("C:\My Documents\Report.xls") ' Add B4DVIS9H.TMP file as "Annual report.doc". mailer.Message.Attachments.Add("C:\DataFiles\B4DVIS9H.TMP", "Annual report.doc")
Smtp Class | MailBee.SmtpMail Namespace