Skip to content

Commit

Permalink
Supporting .Net 4.0 target framework included
Browse files Browse the repository at this point in the history
  • Loading branch information
axunonb committed Sep 24, 2016
1 parent c6f6bf2 commit 45b2b4b
Showing 1 changed file with 1 addition and 145 deletions.
146 changes: 1 addition & 145 deletions MailMergeLib/MailMergeSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,154 +13,10 @@

namespace MailMergeLib
{
public interface IMailMergeSender
{
/// <summary>
/// Returns true, while a Send method is pending.
/// Entering a Send method while IsBusy will raise an InvalidOperationException.
/// </summary>
bool IsBusy { get; }

/// <summary>
/// The settings for a MailMergeSender.
/// </summary>
SenderConfig Config { get; set; }

/// <summary>
/// Sends mail messages asynchronously to all recipients supplied in the data source
/// of the mail merge message.
/// </summary>
/// <param name="mailMergeMessage">Mail merge message.</param>
/// <param name="dataSource">IEnumerable data source with values for the placeholders of the MailMergeMessage.
/// IEnumerable&lt;T&gt; where T can be the following types:
/// Dictionary&lt;string,object&gt;, ExpandoObject, DataRow, class instances or anonymous types.
/// The named placeholders can be the name of a Property, Field, or a parameterless method.
/// They can also be chained together by using &quot;dot-notation&quot;.
/// </param>
/// <remarks>
/// In order to use a DataTable as a dataSource, use System.Data.DataSetExtensions and convert it with DataTable.AsEnumerable()
/// </remarks>
/// <exception>
/// If the SMTP transaction is the cause, SmtpFailedRecipientsException, SmtpFailedRecipientException or SmtpException can be expected.
/// These exceptions throw after re-trying to send after failures (i.e. after MaxFailures * RetryDelayTime).
/// </exception>
/// <exception cref="InvalidOperationException">A send operation is pending.</exception>
/// <exception cref="NullReferenceException"></exception>
/// <exception cref="Exception">The first exception found in one of the async tasks.</exception>
Task SendAsync<T>(MailMergeMessage mailMergeMessage, IEnumerable<T> dataSource);

/// <summary>
/// Sends a single mail message asyncronously.
/// </summary>
/// <remarks>The method raises events before and after sending, as well as on send failure.</remarks>
/// <param name="mailMergeMessage">Mail merge message.</param>
/// <param name="dataItem">The following types are accepted:
/// Dictionary&lt;string,object&gt;, ExpandoObject, DataRow, class instances or anonymous types.
/// The named placeholders can be the name of a Property, Field, or a parameterless method.
/// They can also be chained together by using &quot;dot-notation&quot;.
/// </param>
/// <exception>
/// If the SMTP transaction is the cause, SmtpFailedRecipientsException, SmtpFailedRecipientException or SmtpException can be expected.
/// These exceptions throw after re-trying to send after failures (i.e. after MaxFailures * RetryDelayTime).
/// </exception>
/// <exception cref="InvalidOperationException">A send operation is pending.</exception>
/// <exception cref="AggregateException"></exception>
Task SendAsync(MailMergeMessage mailMergeMessage, object dataItem);

/// <summary>
/// Sends mail messages syncronously to all recipients supplied in the data source
/// of the mail merge message.
/// </summary>
/// <param name="mailMergeMessage">Mail merge message.</param>
/// <param name="dataSource">IEnumerable data source with values for the placeholders of the MailMergeMessage.
/// IEnumerable&lt;T&gt; where T can be the following types:
/// Dictionary&lt;string,object&gt;, ExpandoObject, DataRow, class instances or anonymous types.
/// The named placeholders can be the name of a Property, Field, or a parameterless method.
/// They can also be chained together by using &quot;dot-notation&quot;.
/// </param>
/// <remarks>
/// In order to use a DataTable as a dataSource, use System.Data.DataSetExtensions and convert it with DataTable.AsEnumerable()
/// </remarks>
/// <exception>
/// If the SMTP transaction is the cause, SmtpFailedRecipientsException, SmtpFailedRecipientException or SmtpException can be expected.
/// These exceptions throw after re-trying to send after failures (i.e. after MaxFailures * RetryDelayTime).
/// </exception>
/// <exception cref="InvalidOperationException">A send operation is pending.</exception>
/// <exception cref="SmtpCommandException"></exception>
/// <exception cref="SmtpProtocolException"></exception>
/// <exception cref="AuthenticationException"></exception>
void Send<T>(MailMergeMessage mailMergeMessage, IEnumerable<T> dataSource);

/// <summary>
/// Sends a single mail merge message.
/// </summary>
/// <param name="mailMergeMessage">Message to send.</param>
/// <param name="dataItem">The following types are accepted:
/// Dictionary&lt;string,object&gt;, ExpandoObject, DataRow, class instances or anonymous types.
/// The named placeholders can be the name of a Property, Field, or a parameterless method.
/// They can also be chained together by using &quot;dot-notation&quot;.
/// </param>
/// <exception>
/// If the SMTP transaction is the cause, SmtpFailedRecipientsException, SmtpFailedRecipientException or SmtpException can be expected.
/// These exceptions throw after re-trying to send after failures (i.e. after MaxFailures * RetryDelayTime).
/// </exception>
/// <exception cref="InvalidOperationException">A send operation is pending.</exception>
/// <exception cref="SmtpCommandException"></exception>
/// <exception cref="SmtpProtocolException"></exception>
/// <exception cref="AuthenticationException"></exception>
void Send(MailMergeMessage mailMergeMessage, object dataItem);

/// <summary>
/// Event raising before sending a mail message.
/// </summary>
event EventHandler<MailMessageFailureEventArgs> OnMessageFailure;

/// <summary>
/// Event raising before sending a mail message.
/// </summary>
event EventHandler<MailSenderBeforeSendEventArgs> OnBeforeSend;

/// <summary>
/// Event raising after sending a mail message.
/// </summary>
event EventHandler<MailSenderAfterSendEventArgs> OnAfterSend;

/// <summary>
/// Event raising, if an error occurs when sending a mail message.
/// </summary>
event EventHandler<MailSenderSendFailureEventArgs> OnSendFailure;

/// <summary>
/// Event raising before starting with mail merge.
/// </summary>
event EventHandler<MailSenderMergeBeginEventArgs> OnMergeBegin;

/// <summary>
/// Event raising during mail merge progress, i.e. after each message sent.
/// </summary>
event EventHandler<MailSenderMergeProgressEventArgs> OnMergeProgress;

/// <summary>
/// Event raising after completing mail merge.
/// </summary>
event EventHandler<MailSenderMergeCompleteEventArgs> OnMergeComplete;

/// <summary>
/// Cancel any transactions sending or merging mail.
/// </summary>
/// <param name="waitTime">The number of milliseconds to wait before cancelation.</param>
void SendCancel(int waitTime = 0);

/// <summary>
/// Releases all resources used by MailMergeSender
/// </summary>
void Dispose();
}

/// <summary>
/// Sends MailMergeMessages to an SMTP server. It uses MailKit.Net.Smtp.SmtpClient for low level operations.
/// </summary>
public class MailMergeSender : IDisposable, IMailMergeSender
public class MailMergeSender : IDisposable
{
private bool _disposed;
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
Expand Down

0 comments on commit 45b2b4b

Please sign in to comment.