Solved

sending mail from winform application

Posted on 2007-11-20
4
712 Views
Last Modified: 2012-05-05
Is use .net winform application to send an e-mail via thie code :  
            SmtpClient smtpCli = new SmtpClient();
            smtpCli.Host = SynEmailing.Properties.Settings.Default.SMTP_Host;
            smtpCli.Port = Convert.ToInt32(SynEmailing.Properties.Settings.Default.SMTP_Port);
            smtpCli.Send(htmldoc);

the mail is sent when I close the application  or when i wait for a long time.

how can I do to be sure that the mail is sent when the line smtpcli.send(...) is executed ?

Thanks
0
Comment
Question by:PHD
4 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20318295
by using try catch block only you can do this. I mean put exception handling. Example given below.
  try

  {

            SmtpClient smtpCli = new SmtpClient();

            smtpCli.Host = SynEmailing.Properties.Settings.Default.SMTP_Host;

            smtpCli.Port = Convert.ToInt32(SynEmailing.Properties.Settings.Default.SMTP_Port);

            smtpCli.Send(htmldoc);

  }

  catch (Exception ex)

  {

    MessageBox.Show(ex.Message, "EMail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

  }

Open in new window

0
 
LVL 8

Expert Comment

by:slado2
ID: 20318582
Send is synchronous method. It means that the method blocks execution until the message is sent (or send failed). If you want to send the message asynchronously, call SendAsync.
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 20318743
check your AntiVirus solution. Try to close/stop it the time you make a test.
0
 
LVL 6

Author Closing Comment

by:PHD
ID: 31410075
thanks emoreau
do you have a link or an explanation of what happened ?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A short film showing how OnPage and Connectwise integration works.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now