Click here to Skip to main content
12,998,759 members (70,765 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Friends ;
i want to show progress bar while i sent mail using this code

MailMessage mail=new MailMessage(from,to,subject,body);
                    SmtpClient client=new SmtpClient(smtp);
                    client.Port = 587;
                    client.Credentials = new System.Net.NetworkCredential(from, pass);
                    client.EnableSsl = true;

please help
Posted 29-Jun-13 22:09pm
Updated 29-Jun-13 23:03pm
Maciej Los254.5K
Richard MacCutchan 30-Jun-13 4:11am
Given how quickly those statements will execute it will probably not show on the screen.
Nitesh Luharuka 30-Jun-13 4:51am
You do not have any control on what stage the mail is while being sent . Hence, even if you put a progress bar, it wont show much impact. If you want to send multiple emails showing progress bar, it make sense.
Mike Meinz 30-Jun-13 7:38am
There are no Callbacks from any of the above methods that you could use to update a progress bar. If you really wanted to do a progress bar, you would have to put a line of code in between each of the lines above to update the progress bar by some amount.


MailMessage mail=new MailMessage(from,to,subject,body);
SmtpClient client=new SmtpClient(smtp);
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential(from, pass);
client.EnableSsl = true;

That said, the progress bar will advance so fast that it may not be worth it. How about just change the mouse pointer to an hourglass at the beginning and back to default at the end?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

or Just Send Mail Asynchronous using SendAsync method instead of Send method of SmtpClient

so that control returns immediately.

Display a ProgressBar,
with Style=Marquee,

Handle the SendCompleted event.

and Hide the ProgressBar control (or whatever) in this event, when mail sending is complete.

this will not show the progress of current mail, but at least better than just waiting for its completion.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 30 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100