将邮件发送给数据库表中的所有用户 [英] Send mail to all the user in the Database Table

查看:137
本文介绍了将邮件发送给数据库表中的所有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,,





我想知道我们如何使用数据库表中的所有用户的电子邮件ID发送邮件按钮点击。



当管理员点击emailsendbutton而不是发送给所有用户的邮件

Hello ,,


I want to know how we can send mail to all the user's email id in the database table using button click .

when admin click on the emailsendbutton than the mail sent to all the user

推荐答案

对于发送邮件,您可以使用 System.Net.Mail

样本通过 here [ ^ ]。



现在你所要做的就是,从数据库中获取所有用户,将其存储在 DataTable 中然后,

For sending mail, you can use System.Net.Mail
Sample is given over here[^].

Now all you have to do is, get all the users from the database, store it in DataTable and then,
foreach(DataRow dr in dt.Rows)   // dt is your datatable
{
    SendMailToClient(dr["Email"].ToString());   // SendMailToClient is a method containing logic of sending mail, and takes email address as a parameter, that can easily fetched from DataTable.
}





希望你的流程清楚。

那里这是另一种做法,但是一旦你有了这个想法,你也会有这个,当然:)



-KR



Hope the flow is clear to you.
There is a another way for doing this, but once you got the idea, you'll have that as well, for sure :)

-KR


选择所有用户然后在该rdr.read()中写入此代码



Select All user and then write this code in that rdr.read()

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        Dim m As MailMessage = New MailMessage()
        Dim sc As SmtpClient = New SmtpClient()

        Try

            m.From = New MailAddress("astikajadhav@gmail.com", "Display name")
            m.To.Add(New MailAddress("astikajadhav@gmail.com", "Display name To")) 'to whom mail have to send
            m.Subject = " This is a Test Mail"
            m.IsBodyHtml = True
            m.Body = "Phone number - "
            sc.Host = "smtp.gmail.com"
            sc.Port = 587
            sc.Credentials = New System.Net.NetworkCredential("astikajadhav@gmail.com", "datta-sudhir")
            sc.EnableSsl = True
            sc.Send(m)


            Response.Write("Email Send sucessfully")
        Catch ex As Exception

            Response.Write(ex.Message)

        End Try





肯定会工作

如有问题请



Will work definitely
Any question then ask


试试这个代码:





Try this code:


NetworkCredential cred = new NetworkCredential("gmail@domail.com", "Password");
MailMessage msg = new MailMessage();

msg.To.Add("name@domail.com");


            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    msg.CC.Add((string)dr["user_email"]);
                }
            }


msg.Subject = "Welcome ME";

msg.Body = "You Have Successfully Entered to Sera's World!!!";
msg.From = new MailAddress("mail@domail.com"); // Your Email Id
SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //SMTP Google
SmtpClient client1 = new SmtpClient("smtp.mail.yahoo.com", 465); //SMTP Yahoo
client.Credentials = cred;
client.EnableSsl = true;
client.Send(msg);


这篇关于将邮件发送给数据库表中的所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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