-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from joaopgrassi/bug/26_mimekit_incompletebody
Fix sending emails with MailKit
- Loading branch information
Showing
7 changed files
with
82 additions
and
34 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 |
---|---|---|
|
@@ -23,4 +23,5 @@ obj/ | |
*.sbr | ||
*.scc | ||
*.sig | ||
/packages | ||
/packages | ||
.vs |
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 was deleted.
Oops, something went wrong.
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,76 @@ | ||
using MailKit.Net.Smtp; | ||
using MimeKit; | ||
using netDumbster.smtp; | ||
using netDumbster.smtp.Logging; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace netDumbster.Test | ||
{ | ||
public class MailKitTests : IDisposable | ||
{ | ||
private bool _disposed; | ||
private readonly SimpleSmtpServer _server; | ||
|
||
public MailKitTests() | ||
{ | ||
LogManager.GetLogger = type => new ConsoleLogger(type); | ||
|
||
_server = Configuration.Configure() | ||
.WithRandomPort() | ||
.Build(); | ||
} | ||
|
||
/// <summary> | ||
/// As reported: <see href="https://github.com/cmendible/netDumbster/issues/26"/> | ||
/// </summary> | ||
[Fact] | ||
public async Task Send_WithMailKit_WholeBodyMessageIsPreserved() | ||
{ | ||
var expectedBody = "this is the body\r\nline2\r\nline3"; | ||
|
||
using var client = new SmtpClient | ||
{ | ||
ServerCertificateValidationCallback = (_, __, ___, ____) => true | ||
}; | ||
|
||
await client.ConnectAsync("localhost", _server.Configuration.Port, false).ConfigureAwait(false); | ||
client.AuthenticationMechanisms.Remove("XOAUTH2"); | ||
|
||
var from = new MailboxAddress("carlos@mendible.com"); | ||
var to = new MailboxAddress("karina@mendible.com"); | ||
|
||
var message = new MimeMessage(); | ||
|
||
message.From.Add(from); | ||
message.To.Add(to); | ||
message.Subject = "test"; | ||
message.Body = new TextPart("plain") { Text = expectedBody }; | ||
|
||
client.Send(message); | ||
|
||
Assert.Equal(1, _server.ReceivedEmailCount); | ||
Assert.Equal(expectedBody, _server.ReceivedEmail[0].MessageParts[0].BodyData); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_disposed) | ||
return; | ||
|
||
if (disposing) | ||
{ | ||
_server.Stop(); | ||
} | ||
|
||
_disposed = true; | ||
} | ||
} | ||
} |
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