Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

sending mail from winform application

Posted on 2007-11-20
4
Medium Priority
?
720 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 70

Accepted Solution

by:
Éric Moreau earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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