Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WPF
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 23:09pm
Edited 30-Jun-13 0:03am
Maciej Los164.7K
Richard MacCutchan at 30-Jun-13 4:11am
Given how quickly those statements will execute it will probably not show on the screen.
Nitesh Luharuka at 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 at 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
0 Peter Leow 255
1 Mika Wendelius 240
2 Zoltán Zörgő 208
3 CHill60 195
4 TheRealSteveJudge 180
0 Sergey Alexandrovich Kryukov 8,658
1 OriginalGriff 6,591
2 Peter Leow 3,982
3 Zoltán Zörgő 3,604
4 Richard MacCutchan 2,510

Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 30 Jun 2013
Copyright © CodeProject, 1999-2015
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