Solved

sending mail from winform application

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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