时事通讯大量发送电子邮件 [英] newsletter mass send emails

查看:115
本文介绍了时事通讯大量发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的时事通讯有点麻烦...

让我解释一下:我有一个包含邮件的sql表,别无其他,还有一个sql表,用于在邮件发送后存储邮件,以某种方式不会发送邮件,但是它将保存邮件.

全部都在formview中设置.

Having a little trouble with my Newsletter...

Let me explain: I have a sql table with my emails and nothing else and a sql table where i store the mails after they have been sendt, somehow the mails wont sent, but it will save the mails.

it is all set up in a formview.

protected void btnSendNewsLetter_Click(object sender, EventArgs e)
    {
        TextBox subject = (TextBox)fvNewsletter.Row.FindControl("txtSubject");
        TextBox body = (TextBox)fvNewsletter.Row.FindControl("txtBody");

        string connection = WebConfigurationManager.ConnectionStrings["GreenCollaborationConnectionString"].ConnectionString;

        SqlConnection con = new SqlConnection(connection);

        con.Open();

        SqlCommand comm = new SqlCommand("Select Email from MailingList", con);
        SqlDataAdapter da1 = new SqlDataAdapter(comm);
        GreenDataSet ds1 = new GreenDataSet();
        da1.Fill(ds1);
        if(ds1.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++)
            {
                string email = ds1.Tables[0].Rows[i].ItemArray[0].ToString();
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.From = new MailAddress("noreply@GreenCollaboration.com", "GreenCollaboration");
                mail.To.Add(email);
                mail.Subject = subject.Text;
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                mail.IsBodyHtml = true;
                mail.Body = body.Text;
            }
        }
    }



我希望有人可以帮助我:)



i hope some1 can help me :)

推荐答案

您需要使用
You need to use the SmtpClient class[^] to send the message(s).


您丢失了实际的功能发送.像这样的东西:

You''re missing the bit that does the actual sending. Something like:

using (SmtpClient smtp = new SmtpClient())
{
    smtp.Host = "SMTPServer";
    smtp.Send(mail);
}



您需要稍后适应它,但是它会让您入门.

顺便说一句,您并不是很有效地创建电子邮件.最好有一种方法来封装邮件处理过程,并采用例如一个To地址的集合,而不是一次接收一个.



You''ll need to later that to suit but it''ll get you started.

By the way, you''re not really creating th emails very efficiently. It is better to have a method that encapsulates the mailing process and takes, for instance, a collection of To addresses rather than one at a time.


这篇关于时事通讯大量发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆