Sending Email Asynchronously

I am trying to send 100 emails to myself asynchronously using the code below and I am receiving only few emails (5 emails) instead of 100 . Any help would be appreciated.

Thanks

        using (var client = new SmtpClient())
        {
           int count = 100;
            while (count > 0)
            {
                MailMessage msg = new MailMessage(email, email, "Test" + count, mailMessage.Body);          
                client.Host = smtpServer;
                client.AuthenticationMethod = SmtpAuthentication.None;
               client.BeginSendMessage(msg);          
                count--;
            }
			
		}

Hi Rajesh,

Thank you for contacting Aspose support team.
Please give a try to the following sample code and let us know the feedback.

static public void MainFunction()
{
    SmtpClient client = GetSmtpClient();
    
    for (int i = 0; i < 100; i++)
    {
        MailMessage msg = new MailMessage("username@gmail.com", "username@gmail.com", i + "-Test subject", "Test body");
        
        //Declare msg as MailMessage instance
        SendMail(msg,client);
    }

}

static void SendMail(MailMessage msg, SmtpClient client)
{
    object state = new object();
    IAsyncResult ar = client.BeginSend(msg, Callback, state);
    Console.WriteLine("Sending message... " + msg.Subject);
}

static AsyncCallback Callback = delegate(IAsyncResult ar)
{
    MailClientTask task = (MailClientTask)ar;
    
    if (task.IsCanceled)
    {
        Console.WriteLine("Send canceled.");
    }
    Console.WriteLine("Message Sent.");
};

static SmtpClient GetSmtpClient()
{
    SmtpClient client = new SmtpClient();
    client.Host = "smtp.gmail.com";
    client.Username = "username";
    client.Password = "password";
    client.Port = 587;
    client.SecurityOptions = SecurityOptions.Auto;
    return client;
}