Email not sent until application closes

Posted by Tester101 on Stack Overflow See other posts from Stack Overflow or by Tester101
Published on 2010-05-25T15:55:28Z Indexed on 2010/05/25 16:01 UTC
Read the original article Hit count: 305

Filed under:
|
|

I have an application that uses SmtpClient to send E-Mail, but the E-Mails are not sent until the application closes. I have searched and searched to find a solution to the problem, but I am not able to find one.

The system does have Symantec anti-virus installed, which could possibly be the problem.

Does anybody have a solution to this problem?

Here is the code I am using.

public class EMail
{
    private string server;
    public string Server {get{return this.server;}set{this.server = value;}}
    private string to;
    public string To {get{return this.to;}set{this.to = value;}}
    private string from;
    public string From {get{return this.from;}set{this.from = value;}}
    private string subject;
    public string Subject {get{return this.subject;}set{this.subject = value;}}
    private string body;
    public string Body {get{return this.body;}set{this.body = value;}}

    public EMail()
    {}
    public EMail(string _server, string _to, string _from, string _subject, string _body)
    {
        this.Server = _server;
        this.To = _to;
        this.From = _from;
        this.Subject = _subject;
        this.Body = _body;
    }   

    public void Send()
    {
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(this.From, this.To, this.Subject, this.Body);
        message.IsBodyHtml = true;
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.Server);
        client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        //I have tried this, but it still does not work.
        //client.ServicePoint.ConnectionLeaseTimeout = 0;
        try 
        {
            client.Send(message);
        }  
        catch(System.Exception ex) 
        {
            System.Windows.Forms.MessageBox.Show(ex.ToString());              
        }
        message.Dispose();
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about email