@@ -8,7 +8,7 @@ namespace Shuttle.Pigeon.MailKit;
88
99public class MailKitMessageSender ( IOptions < MailKitOptions > mailKitOptions ) : IMessageSender
1010{
11- private readonly MailKitOptions _mailKitOptions = Guard . AgainstNull ( Guard . AgainstNull ( mailKitOptions ) . Value ) ;
11+ private readonly MailKitOptions _mailKitOptions = Guard . AgainstNull ( mailKitOptions ) . Value ;
1212
1313 public string Channel => "email" ;
1414 public string Name => "mailKit" ;
@@ -27,17 +27,17 @@ public async Task SendAsync(Message message, CancellationToken cancellationToken
2727 {
2828 case RecipientType . To :
2929 {
30- mimeMessage . To . Add ( new MailboxAddress ( recipient . HasDisplayName ? recipient . DisplayName : recipient . Identifier , recipient . Identifier ) ) ;
30+ mimeMessage . To . Add ( new MailboxAddress ( recipient . DisplayName , recipient . Identifier ) ) ;
3131 break ;
3232 }
3333 case RecipientType . Cc :
3434 {
35- mimeMessage . Cc . Add ( new MailboxAddress ( recipient . HasDisplayName ? recipient . DisplayName : recipient . Identifier , recipient . Identifier ) ) ;
35+ mimeMessage . Cc . Add ( new MailboxAddress ( recipient . DisplayName , recipient . Identifier ) ) ;
3636 break ;
3737 }
3838 case RecipientType . Bcc :
3939 {
40- mimeMessage . Bcc . Add ( new MailboxAddress ( recipient . HasDisplayName ? recipient . DisplayName : recipient . Identifier , recipient . Identifier ) ) ;
40+ mimeMessage . Bcc . Add ( new MailboxAddress ( recipient . DisplayName , recipient . Identifier ) ) ;
4141 break ;
4242 }
4343 }
@@ -57,15 +57,14 @@ public async Task SendAsync(Message message, CancellationToken cancellationToken
5757
5858 foreach ( var attachment in message . GetAttachments ( ) )
5959 {
60- using var stream = new MemoryStream ( attachment . Content ) ;
61- await bodyBuilder . Attachments . AddAsync ( attachment . Name , stream , ContentType . Parse ( attachment . ContentType ) , CancellationToken . None ) ;
60+ await bodyBuilder . Attachments . AddAsync ( attachment . Name , new MemoryStream ( attachment . Content ) , ContentType . Parse ( attachment . ContentType ) , CancellationToken . None ) ;
6261 }
6362
6463 mimeMessage . Body = bodyBuilder . ToMessageBody ( ) ;
6564
6665 using var client = new SmtpClient ( ) ;
6766
68- await client . ConnectAsync ( message . FindParameter ( "Host" ) ? . GetValue < string > ( ) ?? _mailKitOptions . Host , message . FindParameter ( "Port" ) ? . GetValue < int > ( ) ?? _mailKitOptions . Port , SecureSocketOptions . StartTls , cancellationToken ) ;
67+ await client . ConnectAsync ( message . FindParameter ( "Host" ) ? . GetValue < string > ( ) ?? _mailKitOptions . Host , message . FindParameter ( "Port" ) ? . GetValue < int > ( ) ?? _mailKitOptions . Port , SecureSocketOptions . Auto , cancellationToken ) ;
6968 await client . AuthenticateAsync ( message . FindParameter ( "Username" ) ? . GetValue < string > ( ) ?? _mailKitOptions . Username , message . FindParameter ( "Password" ) ? . GetValue < string > ( ) ?? _mailKitOptions . Password , cancellationToken ) ;
7069 await client . SendAsync ( mimeMessage , cancellationToken ) ;
7170 await client . DisconnectAsync ( true , cancellationToken ) ;
0 commit comments