MailMerge Class
Contains methods for mail merge; creating multiple messages based on a template message and variable data.
- Inheritance:
- System.ObjectMailMerge
Methods
Merge(MailMessage, IMailMergeDataSource)
Generates a collection of mail messages based on the specified template and populated with provided data.
public static ReadOnlyCollection<MailMessage> Merge(MailMessage template, IMailMergeDataSource dataSource)
Public Shared Function Merge(template As MailMessage, dataSource As IMailMergeDataSource) As ReadOnlyCollection(Of MailMessage)
Parameters
template
- MailMessage
The template mail message.
dataSource
- IMailMergeDataSource
The data source.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<MailMessage>
A read-only collection of mail messages based on the specified template and populated with provided data.
Remarks
Method returns a collection of messages based on the specified template. Strings starting and ending with delimiter (%) are replaced with values from provided data source. These variables can be used in: Subject, BodyText and BodyHtml properties.
note
Data source must contain value named 'To' which represents receiver mail address. Other predefined value names are: 'Cc', 'Bcc' and 'ReplyTo'.
Exceptions
- System.ArgumentNullException
Template is null or Data source is null
Merge(MailMessage, DataTable)
Generates a collection of mail messages based on the specified template and populated with provided data.
public static ReadOnlyCollection<MailMessage> Merge(MailMessage template, DataTable data)
Public Shared Function Merge(template As MailMessage, data As DataTable) As ReadOnlyCollection(Of MailMessage)
Parameters
template
- MailMessage
The template mail message.
data
- System.Data.DataTable
The data source.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<MailMessage>
A read-only collection of mail messages based on the specified template and populated with provided data.
Remarks
Method returns a collection of messages based on the specified template. Strings starting and ending with delimiter (%) are replaced with values from provided data source. These variables can be used in: Subject, BodyText and BodyHtml properties.
note
Data source must contain value named 'To' which represents receiver mail address. Other predefined value names are: 'Cc', 'Bcc' and 'ReplyTo'.
Exceptions
- System.ArgumentNullException
Template is null or Data source is null
Merge<T>(MailMessage, IEnumerable<T>)
Generates a collection of mail messages based on the specified template and populated with provided data.
public static ReadOnlyCollection<MailMessage> Merge<T>(MailMessage template, IEnumerable<T> items)
Public Shared Function Merge(Of T)(template As MailMessage, items As IEnumerable(Of T)) As ReadOnlyCollection(Of MailMessage)
Parameters
template
- MailMessage
The template mail message.
items
- System.Collections.Generic.IEnumerable<T>
The generic list of objects used as data source.
Returns
- System.Collections.ObjectModel.ReadOnlyCollection<MailMessage>
A read-only collection of mail messages based on the specified template and populated with provided data.
Type Parameters
T
The type of data elements in the collection.
Remarks
Method returns a collection of messages based on the specified template. Strings starting and ending with delimiter (%) are replaced with values from provided data source. These variables can be used in: Subject, BodyText and BodyHtml properties.
note
Data source must contain value named 'To' which represents receiver mail address. Other predefined value names are: 'Cc', 'Bcc' and 'ReplyTo'.
Exceptions
- System.ArgumentNullException
Template is null or Data source is null