Solved

sending mail from winform application

Posted on 2007-11-20
4
711 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

21 Experts available now in Live!

Get 1:1 Help Now