-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Добавлена отправка через IMAP. * Исправлены мелкие ошибки. * Рефакторинг.
- Loading branch information
Showing
9 changed files
with
271 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*---------------------------------------------------------- | ||
This Source Code Form is subject to the terms of the | ||
Mozilla Public License, v.2.0. If a copy of the MPL | ||
was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
----------------------------------------------------------*/ | ||
|
||
namespace OneScript.InternetMail | ||
{ | ||
public interface IMailSender | ||
{ | ||
void Logon(InternetMailProfile profile); | ||
void Logoff(); | ||
void Send(InternetMailMessage message, InternetMailTextProcessing processText); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*---------------------------------------------------------- | ||
This Source Code Form is subject to the terms of the | ||
Mozilla Public License, v.2.0. If a copy of the MPL | ||
was not distributed with this file, You can obtain one | ||
at http://mozilla.org/MPL/2.0/. | ||
----------------------------------------------------------*/ | ||
using System; | ||
using MailKit.Net.Smtp; | ||
using MailKit.Security; | ||
|
||
namespace OneScript.InternetMail | ||
{ | ||
public class SmtpSender : IMailSender, IDisposable | ||
{ | ||
|
||
private readonly SmtpClient _client = new SmtpClient(); | ||
|
||
public void Logoff() | ||
{ | ||
if (_client.IsConnected) | ||
_client.Disconnect(true); | ||
} | ||
|
||
public void Logon(InternetMailProfile profile) | ||
{ | ||
SecureSocketOptions options = SecureSocketOptions.Auto; | ||
_client.Timeout = profile.Timeout * 1000; | ||
_client.ServerCertificateValidationCallback = (s, c, h, e) => true; | ||
_client.Connect(profile.SmtpServerAddress, profile.GetSmtpPort(), options); | ||
|
||
if (profile.SmtpUser != "") | ||
_client.Authenticate(profile.SmtpUser, profile.SmtpPassword); | ||
} | ||
|
||
public void Send(InternetMailMessage message, InternetMailTextProcessing processText) | ||
{ | ||
var messageToSend = message.CreateNativeMessage(processText); | ||
_client.Send(messageToSend); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Logoff(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.