多个邮件发送错误 [英] multiple mail sending error

查看:104
本文介绍了多个邮件发送错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要将邮件发送到多个mailid. mailid在数据库中.我通过在gridview.bin中绑定mailid数据库来尝试此操作,并从gridview中将单元格值输入到文本框中.并且我使用该文本框作为我的邮件ID的地址.在此过程中,我仅获得第一个gridview中的mailid数据和发送到该mailid的邮件没有得到下一个下一个mailid数据,我不知道为什么?请帮助我

Hi,
I need to send mail to multiple mailid. the mailid are in database.i tried this by binding the mailid database in gridview.and from gridview in getting the cell value into the textbox.And im using that textbox as my to address of my mail id.in this im getting only the first mailid data in the gridview and the mail send to that mailid its not getting next next mailid data i dnt know why? plz help me

con.Open();
        SqlCommand cmd = new SqlCommand("select * from emailsubscribe", con);
        SqlDataAdapter ada = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        ada.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            for (i = 0; i < dt.Rows.Count; i++)
            {
                TextBox1.Text = GridView1.Rows[0].Cells[1].Text.ToString();
                StringBuilder sb = new StringBuilder();
                MailMessage message = new MailMessage();
                message.From = new MailAddress(TextBox1.Text);
                message.To.Add(new MailAddress(TextBox1.Text));
                message.Subject = "mail subscribe";
                message.Body = "welcome";
                message.IsBodyHtml = true;
                try
                {
                    SmtpClient client = new SmtpClient();
                    client.Host = "smtp.gmail.com";
                    client.Port = 587;
                    client.EnableSsl = true;
                    NetworkCredential credential = new NetworkCredential("id@gmail.com", "password");
                    client.Credentials = credential;
                    client.Send(message);
                }
                catch (Exception ex)
                {
                    Label1.Text = ex.Message;
                }
            }

推荐答案

您不需要GridView和TextBox来发送电子邮件,只需要在DataTable dt中.另外,您已将发件人"和收件人"设置为相同的地址.尝试:
You don''t need GridView and TextBox to send emails, all you need is in you DataTable dt. Also you have set "From" and "To" to same address. Try with:
message.To.Add(dt.Rows[i][1].ToString());


(我不确定索引"1",您没有在查询中列出列名称.)


(I''m not sure about index "1", you didn''t list column names in your query).


如果使用此代码,则
问题是您使用

GridView1.Rows [0] .Cells [1] .Text.ToString();

但您应该使用

GridView1.Rows [i] .Cells [1] .Text.ToString();


您也可以使用

dt.Rows [i] [1] .ToString()代替网格视图
if you use this code then
the problem is that u r using

GridView1.Rows[0].Cells[1].Text.ToString();

but you should use

GridView1.Rows[i].Cells[1].Text.ToString();


also you can use

dt.Rows[i][1].ToString() in place of grid view


这篇关于多个邮件发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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