所以我的问题是我需要从数据库中选择多个电子邮件地址,然后向他们发送电子邮件。 是否可以这样做? 所以基本上我需要字符串sql来查找我需要的电子邮件地址,然后使用DBUTL.SendEmail向这些电子邮件地址发送电子邮件。我该怎么办? 我尝试过:
So my problem is that I need to select multiple email addresses from the database and then send them an email. Is it possible to do that? So basically I need to string sql to find the email addresses that I need and then use DBUTL.SendEmail to send these email addresses an email. How do I do it? What I have tried:
// string sqlB = @"SELECT email, attendees_email FROM Staff S INNER JOIN Staff_have_meetings SHM ON S.staff_id = SHM.staff_id INNER JOIN Meeting M ON M.meeting_id = SHM.meeting_id INNER JOIN Attendees A on A.attendees_id = AHM.attendees_id AND AHM.meeting_id ={0}"; DataTable ds = DBUtl.GetTable(sqlB, TxtMeetingID); string template = EMAIL MESSAGE (Which I have done too); string title = "Cancellation of a meeting"; string link = "SendNotification.aspx"; string message = String.Format(template, link); string result; if (EmailUtl.SendEmail(sqlB, title, message, out result)) { LtlMsg.Text = "Cancellation Email has been sent."; } else { LtlMsg.Text = "Error " + DBUtl.DB_Message; }我会不断收到错误消息,说它不是电子邮件地址。 我该如何处理查询,以便我可以检索电子邮件并将电子邮件发送到选定的电子邮件地址?
I would keep getting error saying it is not in the form of an email address. what do I have to do with the query, so that i can retrieve the email and send email to the selected email addresses?
推荐答案// I'm hard-coding the DataTable for the example // you'll use the DataTable you have and the right column name // for the email field DataTable ds = new DataTable(); ds.Columns.Add("Email", typeof(string)); ds.Rows.Add("email1@domain"); ds.Rows.Add("email2@domain"); ds.Rows.Add("email3@domain"); string emailList = ds.Select() .Select(r => (string)r["Email"]) .Aggregate((a, b) => a = a + ";" + b);
上面的emailList中的现在将包含所有已分隔的电子邮件地址的列表通过分号。
in the above emailList will now contain a list of all email addresses separated by semi-colons.
您可以使用碳复制功能来完成此操作。请参阅下面的代码。 You can do this by using Carbon Copy ability. See code, below. MailMessage mail_IS = new MailMessage("from email address", "TO email address"); mail_IS.IsBodyHtml = true; mail_IS.CC.Add(new MailAddress("hello@world"));
更多推荐
发送电子邮件到从数据库检索的多个电子邮件
发布评论