如何在单独的线程中发送电子邮件?

时间:2015-03-06 09:49:32

标签: multithreading email c#-4.0

我正在从我的网站发送电子邮件,但电子邮件部分很慢, 所以我决定尝试把它放在一个新的线程中, 并想出了这个

    public bool sendmail() 
    {
        Thread T1 = new Thread(delegate()
        {
            MailMessage eMail = new MailMessage();
            SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"]);
            string EmailFromGCBS = (ConfigurationManager.AppSettings["EmailFROM"]);

            eMail.From = new MailAddress(EmailFromGCBS);
            eMail.To.Add(new MailAddress(emailTo));
            eMail.Subject = emailSubject;
            eMail.IsBodyHtml = isHtml;
            eMail.Body = emailBody;
            smtpClient.Send(eMail);

        });
        T1.Start();

        return true;
    }

线程运行,但是没有发送任何电子邮件知道为什么会这样?

0 个答案:

没有答案