Controls the behavior for adding an attachment during the Mail Merge.
The following example uses this table for sample data
| emailaddress | attachmentPath | emailBody |
| bill@mycompany.com | c:\temp\orders\bill.xls | please review your order details |
| steve@hiscompany.com | c:\temp\orders\steve.xls | please review your order details |
| debbie@yourcompany.com | please review your order details |
[C#]
static void Main(string[] args)
{
EmailMessage msg = new EmailMessage();
msg.Server = "mail.mycompany.com";
msg.FromAddress = "me@mycompany.com";
msg.To = "##emailaddress##";
msg.Subject = "see attached orders";
msg.Body = "##emailBody##";
//if the attachment doesn't exist, throw exception.
Attachment a = new Attachment( "##attachmentPath##", AttachmentMMBehavior.ThrowException );
msg.AddAttachment( a );
msg.SendMailMerge( GetAttachmentTable() );
}
public static DataTable GetAttachmentTable()
{
string connectionString = "server=(local);database=northwind;trusted_connection=true;";
string sqlText = "SELECT emailaddress, attachmentPath, emailBody FROM attachmentTable";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter( sqlText, connectionString );
da.Fill( dt );
return dt;
}
[Visual Basic]
Sub Main(ByVal args() As String)
Dim msg As New EmailMessage()
msg.Server = "mail.mycompany.com"
msg.FromAddress = "me@mycompany.com"
msg.To = "##emailaddress##"
msg.Subject = "see attached orders"
msg.Body = "##emailBody##"
'if the attachment doesn't exist, throw exception.
Dim a As New Attachment("##attachmentPath##", AttachmentMMBehavior.ThrowException)
msg.AddAttachment(a)
msg.SendMailMerge(GetAttachmentTable())
End Sub 'Main
Public Function GetAttachmentTable() As DataTable
Dim connectionString As String = "server=(local);database=northwind;trusted_connection=true;"
Dim sqlText As String = "SELECT emailaddress, attachmentPath, emailBody FROM attachmentTable"
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(sqlText, connectionString)
da.Fill(dt)
Return dt
End Function 'GetAttachmentTable
| Member Name | Description |
|---|---|
| ThrowException | Throw an exception if the attachment cannot be found. |
| SendWithoutAttachment | Send the email with out the attachment. |
| DoNotSend | Do not send the email, but continue on with the Mail Merge process |
Namespace: aspNetEmail
Assembly: aspNetEmail (in aspNetEmail.dll)