发送电子邮件到从数据库检索的多个电子邮件

编程入门 行业动态 更新时间:2024-10-09 10:31:42
本文介绍了发送电子邮件到从数据库检索的多个电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我的问题是我需要从数据库中选择多个电子邮件地址,然后向他们发送电子邮件。 是否可以这样做? 所以基本上我需要字符串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"));

更多推荐

发送电子邮件到从数据库检索的多个电子邮件

本文发布于:2023-10-12 16:17:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   发送电子邮件   电子邮件   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!