Built-in Mail Merge Support in WebTextEditor

Many people are familiar with Mail Merge feature in Microsoft Word. It is used when you want to send a set of documents that has the same kind of information, but personalized for each recipient. For example: you want to send a gathering invitation to all members of IT division. You can send the invitation to all members using the same template but personalized for each recipient. This feature is also supported in WebTextEditor.

You can enable this feature instantly by setting the EnableMailMerge property available in MailMergeSettings. The collection of recipients can be specified as data bound collection or custom collection. When data bound collection is used, the datasource control id can be specified as DataSourceID property.

When custom collection is used, the collection can be added to Recipients collection.

When the collection of recipients are ready, you need to specify the labels. Labels are used to indicate parts of the content that will be replaced with the related data in the data context. You can specify as many labels as needed in the template. Each label contain the following properties:

  • Label (mandatory): specifies the text used as label.
  • DataMember (mandatory): specifies the field or property in data context that will be used to replace the label text.
  • FormatString (optional): specifies the format string of the label. This property can be specified if you want to have a specific format on dates or numbers.

The collection of labels can be added in MailMergeSettings >> Labels property.

Insert Labels

The labels will be added to Insert Merge Label dropdown in main toolbar. Users can easily select an item from this command in main toolbar and it will be added to editor. Users will not be able to modify the labels manually in the editor window.

Collections of labels added to toolbar

Users can preview the mail merge result in Preview tab. The labels will be automatically replaced with the related data in the data context and users can navigate through the data using the previous and next commands in toolbar.

Preview Mail Merge content

Users can also send the mail using Send Mail Merge command. Some related properties that need to be configured are:

  • EmailField: specifies the field or property in data context that contains email data.
  • From: specifies the email of sender.
  • IsHTML: specifies whether or not the email should be sent as HTML format.
  • MailPriority: specifies the priority status of the email.
  • SMTP: specifies the SMTP server.
  • SubjectExpression: specifies the subject of the email. Labels can be included as the value of this property and they will automatically be replaced with related data when the email is sent.

Mail Merge configuration

WebTextEditor provides various server-side events that will be invoked when the emails are about to be sent. If you have specific scenarios that need custom actions, these events can be used to implement those actions.

  • OnBeforeSendMail event is invoked the emails are sent.
  • OnMailMerge event is invoked when each email is merged with the related data from data context.
  • OnMailMergeCompleted event is invoked when all emails have been merged with the related data from the data context.
  • OnSendMail event is invoked when each email is about to be sent.
  • OnSendMailCompleted event is invoked after all emails are sent.

If you set AutomaticSendMail property to False, you can specify your own configuration and send mail process in OnSendMail event.

After all emails are sent, you might need to display specific custom status in WebTextEditor or perform other custom actions in client-side. In this case, you can use OnSendMailCompleted client-side event. In this event, the failed emails data will also be passed as parameters. So, in cases where emails are failed to be sent to recipients, you can perform custom actions to handle the scenario.

If you have feedback regarding this feature, feel free to drop a comment or create a new discussion in our new Forum.

Leave a Reply