aspNetEmail

AttachmentMMBehavior Enumeration

Controls the behavior for adding an attachment during the Mail Merge.

public enum AttachmentMMBehavior

Remarks

The following example uses this table for sample data

emailaddressattachmentPathemailBody
bill@mycompany.comc:\temp\orders\bill.xlsplease review your order details
steve@hiscompany.comc:\temp\orders\steve.xlsplease review your order details
debbie@yourcompany.complease review your order details

Example

[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
            
            

Members

Member NameDescription
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

Requirements

Namespace: aspNetEmail

Assembly: aspNetEmail (in aspNetEmail.dll)

See Also

aspNetEmail Namespace