SHARE
TWEET

Untitled

a guest Jul 15th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected void Send( )
  2.     {
  3.         var messages = new List<MimeMessage>( );
  4.  
  5.         for( int i = 1; i < 4; i++ )
  6.         {
  7.             var message = new MimeMessage
  8.             {
  9.                 Sender = new MailboxAddress( "Sender Name", "Sender Email Address" ),
  10.                 Subject = "Test email " + i.ToString( ),
  11.                 Body = new TextPart( TextFormat.Html ) { Text = "Test body " + i.ToString( ) }
  12.             };
  13.             message.To.Add( new MailboxAddress( "test" + i.ToString( ) + "@example.com" ) );
  14.             messages.Add( message );
  15.         }
  16.  
  17.         MailNew.SendMultipleAsyncMails( messages );
  18.     }
  19.      
  20. public static void SendMultipleAsyncMails( List<MimeMessage> messages )
  21.     {
  22.         Task t = Task.Run( async ( ) =>
  23.         {
  24.             using( var client = new SmtpClient( ) )
  25.             {
  26.                 await client.ConnectAsync( "Host", 587, SecureSocketOptions.StartTls );
  27.                 await client.AuthenticateAsync( "UserName", "Password" );
  28.                 foreach( var message in messages )
  29.                 {
  30.                     await client.SendAsync( message );
  31.                     await Task.Delay( 10000 );
  32.                 }
  33.                 await client.DisconnectAsync( true );
  34.             }
  35.         } );
  36.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top