BeginBulkSend with EndBulkSend

Hi,

Can you give me a sample or a link which describes the usage of ‘BeginBulkSend’ paired with ‘EndBulksend’ ??

thanking you in advance
Jaz

Hi Jaz,

Please view the following code sample for the usage of BeginBulkSend() paired with EndBulkSend().

///


/// BeginBulkSend with EndBulkSend demo
///

public void PerformBulkSend()
{
try
{
//Create SmtpClient
SmtpClient client = new SmtpClient("smtp.server.com", 25, "sender@domain.com", "password");
//Create all your messages
MailMessage msg1 = new MailMessage("sender@domain.com", "recepient@domain.com", "msg1", "test1");
MailMessage msg2 = new MailMessage("sender@domain.com", "recepient@domain.com", "msg2", "test2");
MailMessage msg3 = new MailMessage("sender@domain.com", "recepient@domain.com", "msg3", "test3");

// this is the deligate that registers callback function
AsyncCallback callBack = new AsyncCallback(bulkMessagesSent);
object objState = new object(); // state object

// MailMessageCollection class that contains all the messages
MailMessageCollection manyMsg = new MailMessageCollection();
manyMsg.Add(msg1);
manyMsg.Add(msg2);
manyMsg.Add(msg3);

// send the bulk emails
IAsyncResult result = client.BeginBulkSend(manyMsg, callBack, objState);

// suppose you want to cancel the above asynchronous request
// pass the result object as an argument to EndBulkSend() method
client.EndBulkSend(result);
Console.WriteLine("Main method finished.");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

///


/// callback function that is called automatically
/// when asynchronous function BeginBulkSend() finishes
///

///
private void bulkMessagesSent(IAsyncResult result)
{
// this message will be displayed when the bulk send operation completes
Console.WriteLine("BeginBulkSend() complete.");
}

Regards,
Saqib Razzaq

Hello,

Our support engineer will post a sample for your shortly.

Best regards