1- using System . Collections . Generic ;
2- using System . Net . Mail ;
1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Threading ;
34using System . Threading . Tasks ;
5+ using MailKit . Net . Smtp ;
6+ using MimeKit ;
47using Simplify . Mail . Settings ;
58
69namespace Simplify . Mail ;
710
811/// <summary>
912/// Represent E-mail sending interface.
1013/// </summary>
11- public interface IMailSender
14+ public interface IMailSender : IDisposable
1215{
1316 /// <summary>
1417 /// MailSender settings.
@@ -25,31 +28,33 @@ public interface IMailSender
2528 /// Send single e-mail.
2629 /// </summary>
2730 /// <param name="client">Smtp client.</param>
28- /// <param name="mailMessage ">The mail message.</param>
31+ /// <param name="mimeMessage ">The MIME message.</param>
2932 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
30- void Send ( SmtpClient client , MailMessage mailMessage , string bodyForAntiSpam = null ) ;
33+ void Send ( SmtpClient client , MimeMessage mimeMessage , string bodyForAntiSpam = null ) ;
3134
3235 /// <summary>
3336 /// Send single e-mail asynchronously.
3437 /// </summary>
3538 /// <param name="client">Smtp client.</param>
36- /// <param name="mailMessage ">The mail message.</param>
39+ /// <param name="mimeMessage ">The MIME message.</param>
3740 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
38- Task SendAsync ( SmtpClient client , MailMessage mailMessage , string bodyForAntiSpam = null ) ;
41+ /// <param name="cancellationToken">The cancellation token.</param>
42+ Task SendAsync ( SmtpClient client , MimeMessage mimeMessage , string bodyForAntiSpam = null , CancellationToken cancellationToken = default ) ;
3943
4044 /// <summary>
4145 /// Send single e-mail.
4246 /// </summary>
43- /// <param name="mailMessage ">The mail message.</param>
47+ /// <param name="mimeMessage ">The MIME message.</param>
4448 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
45- void Send ( MailMessage mailMessage , string bodyForAntiSpam = null ) ;
49+ void Send ( MimeMessage mimeMessage , string bodyForAntiSpam = null ) ;
4650
4751 /// <summary>
4852 /// Send single e-mail asynchronously.
4953 /// </summary>
50- /// <param name="mailMessage ">The mail message.</param>
54+ /// <param name="mimeMessage ">The MIME message.</param>
5155 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
52- Task SendAsync ( MailMessage mailMessage , string bodyForAntiSpam = null ) ;
56+ /// <param name="cancellationToken">The cancellation token.</param>
57+ Task SendAsync ( MimeMessage mimeMessage , string bodyForAntiSpam = null , CancellationToken cancellationToken = default ) ;
5358
5459 /// <summary>
5560 /// Send single e-mail.
@@ -65,7 +70,7 @@ public interface IMailSender
6570 /// Process status, <see langword="true" /> if message is processed to sent successfully
6671 /// </returns>
6772 void Send ( SmtpClient client , string from , string to , string subject , string body , string bodyForAntiSpam = null ,
68- params Attachment [ ] attachments ) ;
73+ params MimeEntity [ ] attachments ) ;
6974
7075 /// <summary>
7176 /// Send single e-mail asynchronously.
@@ -77,11 +82,12 @@ void Send(SmtpClient client, string from, string to, string subject, string body
7782 /// <param name="body">e-mail body.</param>
7883 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
7984 /// <param name="attachments">The attachments to an e-mail.</param>
85+ /// <param name="cancellationToken">The cancellation token.</param>
8086 /// <returns>
8187 /// Process status, <see langword="true" /> if message is processed to sent successfully
8288 /// </returns>
8389 Task SendAsync ( SmtpClient client , string from , string to , string subject , string body , string bodyForAntiSpam = null ,
84- params Attachment [ ] attachments ) ;
90+ MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
8591
8692 /// <summary>
8793 /// Send single e-mail.
@@ -94,7 +100,7 @@ Task SendAsync(SmtpClient client, string from, string to, string subject, string
94100 /// <param name="attachments">The attachments to an e-mail.</param>
95101 /// <returns>Process status, <see langword="true"/> if message is processed to sent successfully</returns>
96102 void Send ( string from , string to , string subject , string body , string bodyForAntiSpam = null ,
97- params Attachment [ ] attachments ) ;
103+ params MimeEntity [ ] attachments ) ;
98104
99105 /// <summary>
100106 /// Send single e-mail asynchronously.
@@ -105,9 +111,10 @@ void Send(string from, string to, string subject, string body, string bodyForAnt
105111 /// <param name="body">e-mail body.</param>
106112 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
107113 /// <param name="attachments">The attachments to an e-mail.</param>
114+ /// <param name="cancellationToken">The cancellation token.</param>
108115 /// <returns>Process status, <see langword="true"/> if message is processed to sent successfully</returns>
109116 Task SendAsync ( string from , string to , string subject , string body , string bodyForAntiSpam = null ,
110- params Attachment [ ] attachments ) ;
117+ MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
111118
112119 /// <summary>
113120 /// Send e-mail to multiple recipients in one e-mail.
@@ -121,7 +128,7 @@ Task SendAsync(string from, string to, string subject, string body, string bodyF
121128 /// <param name="attachments">The attachments to an e-mail.</param>
122129 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
123130 void Send ( SmtpClient client , string fromMailAddress , IList < string > addresses , string subject , string body ,
124- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
131+ string bodyForAntiSpam = null , params MimeEntity [ ] attachments ) ;
125132
126133 /// <summary>
127134 /// Send e-mail to multiple recipients in one e-mail asynchronously.
@@ -133,9 +140,10 @@ void Send(SmtpClient client, string fromMailAddress, IList<string> addresses, st
133140 /// <param name="body">e-mail body.</param>
134141 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
135142 /// <param name="attachments">The attachments to an e-mail.</param>
143+ /// <param name="cancellationToken">The cancellation token.</param>
136144 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
137145 Task SendAsync ( SmtpClient client , string fromMailAddress , IList < string > addresses , string subject , string body ,
138- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
146+ string bodyForAntiSpam = null , MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
139147
140148 /// <summary>
141149 /// Send e-mail to multiple recipients in one e-mail.
@@ -148,7 +156,7 @@ Task SendAsync(SmtpClient client, string fromMailAddress, IList<string> addresse
148156 /// <param name="attachments">The attachments to an e-mail.</param>
149157 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
150158 void Send ( string fromMailAddress , IList < string > addresses , string subject , string body ,
151- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
159+ string bodyForAntiSpam = null , params MimeEntity [ ] attachments ) ;
152160
153161 /// <summary>
154162 /// Send e-mail to multiple recipients in one e-mail asynchronously.
@@ -159,9 +167,10 @@ void Send(string fromMailAddress, IList<string> addresses, string subject, strin
159167 /// <param name="body">e-mail body.</param>
160168 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
161169 /// <param name="attachments">The attachments to an e-mail.</param>
170+ /// <param name="cancellationToken">The cancellation token.</param>
162171 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
163172 Task SendAsync ( string fromMailAddress , IList < string > addresses , string subject , string body ,
164- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
173+ string bodyForAntiSpam = null , MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
165174
166175 /// <summary>
167176 /// Send e-mail to multiple recipients and carbon copy recipients in one e-mail.
@@ -176,7 +185,7 @@ Task SendAsync(string fromMailAddress, IList<string> addresses, string subject,
176185 /// <param name="attachments">The attachments to an e-mail.</param>
177186 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
178187 void Send ( SmtpClient client , string fromMailAddress , IList < string > addresses , IList < string > ccAddresses ,
179- string subject , string body , string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
188+ string subject , string body , string bodyForAntiSpam = null , params MimeEntity [ ] attachments ) ;
180189
181190 /// <summary>
182191 /// Send e-mail to multiple recipients and carbon copy recipients in one e-mail asynchronously.
@@ -189,9 +198,10 @@ void Send(SmtpClient client, string fromMailAddress, IList<string> addresses, IL
189198 /// <param name="body">e-mail body.</param>
190199 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
191200 /// <param name="attachments">The attachments to an e-mail.</param>
201+ /// <param name="cancellationToken">The cancellation token.</param>
192202 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
193203 Task SendAsync ( SmtpClient client , string fromMailAddress , IList < string > addresses , IList < string > ccAddresses ,
194- string subject , string body , string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
204+ string subject , string body , string bodyForAntiSpam = null , MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
195205
196206 /// <summary>
197207 /// Send e-mail to multiple recipients and carbon copy recipients in one e-mail.
@@ -204,7 +214,8 @@ Task SendAsync(SmtpClient client, string fromMailAddress, IList<string> addresse
204214 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
205215 /// <param name="attachments">The attachments to an e-mail.</param>
206216 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
207- void Send ( string fromMailAddress , IList < string > addresses , IList < string > ccAddresses , string subject , string body , string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
217+ void Send ( string fromMailAddress , IList < string > addresses , IList < string > ccAddresses , string subject , string body ,
218+ string bodyForAntiSpam = null , params MimeEntity [ ] attachments ) ;
208219
209220 /// <summary>
210221 /// Send e-mail to multiple recipients and carbon copy recipients in one e-mail asynchronously.
@@ -216,9 +227,10 @@ Task SendAsync(SmtpClient client, string fromMailAddress, IList<string> addresse
216227 /// <param name="body">e-mail body.</param>
217228 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
218229 /// <param name="attachments">The attachments to an e-mail.</param>
230+ /// <param name="cancellationToken">The cancellation token.</param>
219231 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
220232 Task SendAsync ( string fromMailAddress , IList < string > addresses , IList < string > ccAddresses , string subject , string body ,
221- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
233+ string bodyForAntiSpam = null , MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
222234
223235 /// <summary>
224236 /// Send e-mail to multiple recipients separately
@@ -232,7 +244,7 @@ Task SendAsync(string fromMailAddress, IList<string> addresses, IList<string> cc
232244 /// <param name="attachments">The attachments to an e-mail.</param>
233245 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
234246 void SendSeparately ( SmtpClient client , string fromMailAddress , IList < string > addresses , string subject , string body ,
235- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
247+ string bodyForAntiSpam = null , params MimeEntity [ ] attachments ) ;
236248
237249 /// <summary>
238250 /// Send e-mail to multiple recipients separately
@@ -244,9 +256,10 @@ void SendSeparately(SmtpClient client, string fromMailAddress, IList<string> add
244256 /// <param name="body">e-mail body.</param>
245257 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
246258 /// <param name="attachments">The attachments to an e-mail.</param>
259+ /// <param name="cancellationToken">The cancellation token.</param>
247260 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
248261 Task SendSeparatelyAsync ( SmtpClient client , string fromMailAddress , IList < string > addresses , string subject , string body ,
249- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
262+ string bodyForAntiSpam = null , MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
250263
251264 /// <summary>
252265 /// Send e-mail to multiple recipients separately
@@ -259,7 +272,7 @@ Task SendSeparatelyAsync(SmtpClient client, string fromMailAddress, IList<string
259272 /// <param name="attachments">The attachments to an e-mail.</param>
260273 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
261274 void SendSeparately ( string fromMailAddress , IList < string > addresses , string subject , string body ,
262- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
275+ string bodyForAntiSpam = null , params MimeEntity [ ] attachments ) ;
263276
264277 /// <summary>
265278 /// Send e-mail to multiple recipients separately
@@ -270,7 +283,8 @@ void SendSeparately(string fromMailAddress, IList<string> addresses, string subj
270283 /// <param name="body">e-mail body.</param>
271284 /// <param name="bodyForAntiSpam">Part of an e-mail body just for anti-spam checking.</param>
272285 /// <param name="attachments">The attachments to an e-mail.</param>
286+ /// <param name="cancellationToken">The cancellation token.</param>
273287 /// <returns>Process status, <see langword="true"/> if all messages are processed to sent successfully</returns>
274288 Task SendSeparatelyAsync ( string fromMailAddress , IList < string > addresses , string subject , string body ,
275- string bodyForAntiSpam = null , params Attachment [ ] attachments ) ;
276- }
289+ string bodyForAntiSpam = null , MimeEntity [ ] attachments = null , CancellationToken cancellationToken = default ) ;
290+ }
0 commit comments