使用ASP.NET和MS SQL 2008数据库向所有用户列表发送电子邮件 [英] Sending E-mail to All List of Users with ASP.NET and MS SQL 2008 database

查看:113
本文介绍了使用ASP.NET和MS SQL 2008数据库向所有用户列表发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



创建电子邮件功能的主要工作范围分别向每个用户发送电子邮件但它会发送给所有用户(所有用户名都显示在 To 属性中。有一个问题需要完成此操作。



这是代码中的片段:



Hi All,

The main scope of my task to create the email functionality to send the e-mail to every each user separately but it sends to all users(all user names are display in To property. Having a problem to accomplish this.

Here's the fragment on the code:

ArrayList list_emails = new ArrayList();
    int i = 0;
    string email  = null;
..................................
db Conncetion; datareader; call stored proc;
..................................

ReaderEL = custTable_db.ExecuteReader(dbCommand);
//Loop through reader and add settlement details to arraylist
while (ReaderEL.Read())
{
    list_emails.Add(ReaderEL.GetValue(0).ToString());
    i = i + 1;
}

       MailMessage objMail = new MailMessage();
       SmtpClient mSmtpClient = new SmtpClient();

foreach (string email_to in list_emails)                      
       {
                                                                  
         objMail.From = new MailAddress("noreply@abc.com");
         objMail.To.Add(new MailAddress(email_to));
         objMail.Subject = txtSubject.Text.Trim();
         objMail.Body = ftbEmailMesg.Text;
         objMail.Priority = MailPriority.Normal;
         objMail.IsBodyHtml = true;
         mSmtpClient.Host = "00.000.0.000";
         mSmtpClient.Send(objMail);              
        }



感谢任何帮助!


Appreciate any help!

推荐答案

如果你发送的话会有什么不同一条消息到地址列表?只有一个:所有收件人都会知道所有其他收件人。



所以,我可以假设这是你向每个用户发送它的原因单独,以保密其他用户。我看不出其他原因。


如果是这样,你有两个选择1)只将一个地址放到To:标题中,另一个地址放到BCC:标题,使该列表的内容发送给每个参与者; 2)在循环中发送单独消息的列表,仅更改To:标题,每次迭代只有一个地址(没有奇迹:-))。



-SA
What's would make the difference if you send just one message to a list of addresses? Only one: all the recipients would be aware of all other recipients.

So, I can assume this is the reason you might have for sending it "to every each user separately", to keep other users in secret. I cannot see other reasons.

If so, you have two options 1) put just one address to the "To:" header and other addressed to "BCC:" header, which makes the content of this list to be sent to each participant; 2) send a list of separate messages in a loop, changing only the "To:" header, with only one address on each iteration (there is no such thing as miracle :-)).

—SA


这就是为什么你需要使用ASP.NET这样做的原因,如前所述你可以使用循环,将其发送给所有收件人,唯一的单个邮件。例如



That is why you need to use the ASP.NET way of doing this, as already mentioned you can use a loop, to send it to all of the recipients, the only single message. For example

foreach (var recipient in recipients) {
  // send the email
}





这是一个可以实现的示例代码如下,





This is an example code which can be implemented as follows,

// example array of recipients 
var recipients = {"array@example.com", "ofrecipients@example.com"};
// now loop through the recipients, 
foreach (var recipient in recipients) {
  // use the WebMail class, 
  WebMail.Send(to: recipient,
               subject: "Subject of the Email",
               body: "The message of the email."
               );
}





一旦结束,电子邮件将发送给您将通过的列表或数组中的用户循环。在循环中,字段是一个变量,取决于循环传递的值。



您可以从我几个月写回来的文章中学习如何使用ASP.NET WebMail类发送电子邮件,轻松使用ASP.NET助手发送电子邮件 [ ^ ]



替代方式



还有另外一种方法,即将BCC(盲碳复制)附加到电子邮件这不会向其他收件人透露收件人的信息,但不是一个好方法,因为您不知道您可能拥有多少电子邮件收件人等等。因此,使用循环并传递收件人的电子邮件地址值将是更好的出价。



Once this ends, the emails would be send to the users, in the list or array that you will pass to the loop. In the loop, to field is a variable and depends on the value passed by the loop.

You can learn how to send emails using ASP.NET WebMail class from an article I wrote back a few months, Sending Emails Easily Using ASP.NET Helpers[^]

Alternate way

There is another way, of doing this, that is to attach a BCC (Blind Carbon Copy) to the email this would not reveal the recipient's information to other recipients, but will not be a good way, since you don't know how many email recipients you might have and so on. So using a loop and passing values of email address of the recipients will be a better bid for this.


这篇关于使用ASP.NET和MS SQL 2008数据库向所有用户列表发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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