此代码一次成功发送一封电子邮件。
我的问题是在点击Button2
时停止发送电子邮件。单击Button2
后,计时器会成功显示确认Session["stop"].Equals("true")
的消息。
但是,电子邮件没有停止..任何帮助?
protected void Button2_Click(object sender, EventArgs e)
{
Session["stop"] = "true";
}
private void email()
{
for (int i = 1; i <= amount; i++)
{
Thread email = new Thread(delegate ()
{
SendMail(to, from, password, subject, body, amount);
});
email.IsBackground = true;
email.Start();
if (Session["stop"].Equals("true"))
{
email.Abort();
return;
}
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if (Session["stop"].Equals("true"))
{
Label1.Text = "Mail stopped. Sent: " + allMailSent;
Session["stop"] = "false";
}
}