如何向多个收件人发送电子邮件 [英] How to send email to multiple recipients

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

问题描述





我正在建立网络服务。我需要通过代码逻辑发送电子邮件。

例如:用户将向网络服务器发送请求。他将通过选中复选框来选择多个收件人。网络服务器将获取收件人姓名和电子邮件ID列表。所以请帮助我,通过代码,我将能够发送邮件给多个收件人。



提前谢谢。

Hi,

I am building the webservice. I need to send email logically through code.
For example : The User will send a request to webserver. He will choose Multiple recipients by selecting the check boxes. The webserver will get the recipients name and email id list. So please help me that, through code i will be able to send a mail to multiple recipients.

Thanks in advance.

推荐答案

这里有一个发送电子邮件的通用例程:使用或不使用附件在C#中发送电子邮件:通用例程。 [ ^ ]

您所要做的就是添加更多收件人地址,或者改为使用CC / BCC列表。
There is a generic routine here for sending email: Sending an Email in C# with or without attachments: generic routine.[^]
All you have to do is add more "To" addresses, or use the CC / BCC list instead.


试试这个:



命名空间:

Try this:

Namespaces:
using System.Collections; //ArrayList
using System.Data.SqlClient; //SQL
using System.Net.Mail; //email



代码:


Code:

private void btnSend_Email_Click(object sender, EventArgs e)
        {
            ArrayList list_emails = new ArrayList();
            int i = 0, email = 0;
            sqlConnection1.Open(); //connection to the database.
            SqlCommand cmd_Email = new SqlCommand("Select Email from Email_Table", sqlConnection1);
            SqlDataReader read_Email = cmd_Email.ExecuteReader();
            while (read_Email.Read())
            {
                email = read_Email.GetValue(i).ToString();
                list_emails.Add(email); //Add email to a arraylist
                i = i + 1 - 1; //increment or ++i
            }
            read_Email.Close();
            sqlConnection1.Close(); //Close connection
 
            foreach (string email_to in list_emails)
            {
                MailMessage mail = new MailMessage();
                mail.To.Add(email_to);
                mail.Subject = "Welcome to C#";
                mail.From = new MailAddress(hold_Account);
                mail.Body = "Test";
                SmtpClient smtp = new SmtpClient("SMTP Server");
                smtp.Send(mail);
            }



参考:向多个电子邮件地址发送电子邮件 [ ^ ]


Ref.: send email to multiple email addresses [^]


您可以将所有电子邮件ID以逗号分隔在地址。然后发送给您将能够发送多个收件人。
You can have all the email ids comma separated in the to address. And then send you will be able to send for multiple recipients.


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

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