Solved

sending mail from winform application

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 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