-
Notifications
You must be signed in to change notification settings - Fork 32
Sender
var mms = new MailMergeSender() {Config = Settings.Deserialize("path-to-settings.config").SenderConfig};
The configuration of a MailMergeSender
is covered in the Settings section of the documentation.
Have a closer look especially at the fail-over capabilities of MailMergeSender
, e.g.:
- Configure a standard SMTP client
- Configure a backup SMTP client
- Configure a desaster SMTP client which writes messages to the file system
- Configure the number of SMTP clients to use
Send a single mail message with a single data item:
var singleDataItem = new Dictionary<string, string> { {"Email", "[email protected]"}, {"Name", "John Specimen"} };
await mms.SendAsync(mailMergeMessage, (object) singleDataItem);
Send mail messages to with a several data items:
var enumerableOfDataItems = new[]
{
new { Email = "[email protected]", Name = "John Specimen" },
new { Email = "[email protected]", Name = "Mary Specimen" }
};
await mms.SendAsync(mailMergeMessage, enumerableOfDataItems);
Send a single mail message with a single data item:
var singleDataItem = new Dictionary<string, string> { {"Email", "[email protected]"}, {"Name", "John Specimen"} };
mms.Send(mailMergeMessage, (object) singleDataItem);
Send mail messages to with a several data items:
var enumerableOfDataItems = new[]
{
new { Email = "[email protected]", Name = "John Specimen" },
new { Email = "[email protected]", Name = "Mary Specimen" }
};
mms.Send(mailMergeMessage, enumerableOfDataItems);
The MailMergeSender.IsBusy
property indicates that a send process has been started and this instance is busy. Calling one of the send methods while IsBusy == true
will throw an exception.
Here is the description of all events you can subscribe to from a MailMergeSender
instance.
var mms = new MailMergeSender() {Config = Settings.Deserialize("path-to-settings.config").SenderConfig};
// Event raising before merging starts
mms.OnMergeBegin += (mailMergeSender, mergeBeginArgs) => { };
Event arguments let you observe
- start time
- total messages to send
// Event raising when getting the merged MimeMessage of the MailMergeMessage has failed.
mms.OnMessageFailure += (mailMergeSender, messageFailureArgs) => { };
Event arguments let you observe and tackle failures during message generation.
- MailMergeMessage
- The data source which was involved during message generation
- An AggregateException with all reasons in detail why it was thrown, and a MimeMessage, as far as it could be generated.
- A MimeMessage parameter which can be returned to the caller.
- A bool parameter to decide whether the sender should raise a MailMergeMessageException
See more details in chapter Message Error Handling.
// Event raising before sending a single mail message starts
mms.OnBeforeSend += (smtpClient, beforeSendArgs) => { };
Event arguments let you observe
- start time
- SmtpClientConfig
- MimeMessage
- exception (if any)
// Event raising right after the SmtpClient's connection to the server is up (but not yet authenticated).
mms.OnSmtpConnected += (smtpClient, smtpClientArgs) => { };
Event arguments let you observe the SmtpClientConfig
.
// Event raising after the SmtpClient has authenticated on the server.
mms.OnSmtpAuthenticated += (smtpClient, smtpClientArgs) => { };
Event arguments let you observe the SmtpClientConfig
.
Will only raise if authentification is requested from SMTP mail server.
// Event raising after the SmtpClient has disconnected from the SMTP mail server.
mms.OnSmtpDisconnected += (smtpClient, smtpClientArgs) => { };
Event arguments let you observe the SmtpClientConfig
.
// Event raising if sending a single mail message fails
mms.OnSendFailure += (smtpClient, sendFailureArgs) => { };
Event arguments let you observe
- exception
- failure counter for this MimeMessage
- MimeMessage
- SmtpClientConfig
// Event raising before sending a single mail message is finished
mms.OnAfterSend += (smtpClient, afterSendArgs) => { };
Event arguments let you observe
- start time
- end time
- MimeMessage
- SmtpClientConfig
- exception (if any)
// Event raising each time a single message was sent successfully
mms.OnMergeProgress += (mailMergeSender, progressArgs) => { };
Event arguments let you observe
- start time
- total messages
- sent messages till then
- error messages till then
// Event raising after merging is completed
mms.OnMergeComplete += (mailMergeSender, completedArgs) => { };
};
Event arguments let you observe
- start time
- end time
- total messages
- sent messages
- error messages
- number of SmtpClients used