SmtpAddAttachment Method
Reads the specified file from disk and adds it as attachment to the message.

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
public bool AddAttachment(
	string filename


Type: SystemString
The full path and filename of the file to be attached.

Return Value

Type: Boolean
true if the method succeeds; otherwise, false.
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Smtp.AddAttachment method is equivalent to Smtp.Message.Attachments.Add method (see Add(String)).

The developer can use overloads of Add(Attachment) method to add attachments in an advanced way (memory or stream attachments, attachments of a specific type, etc).

Note 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.
Adding an attachment to the message using Smtp.AddAttachment and Smtp.Message.Attachments.Add methods.
// 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");
See Also