Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 = "http://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?
Posted
Updated 26-Jun-18 11:20am
v2
Comments
F-ES Sitecore 25-Jan-18 4:42am    
You'll probably need to loop through the dataset and send an individual email to each person

string html = "my email"
foreach (record in results)
{
Sendemail to record["recipient address"]
}

You haven't provided enough code to give a specific example of what you need to do.
dibdab 25-Jan-18 6:18am    
I am not very sure how to code it yet.. but basically I need to retrieve the value from the database with the query.. and then combine them with ";" and send them an email..
F-ES Sitecore 25-Jan-18 6:20am    
That's generally considered a bad idea as it reveals the email addresses of other people to the list. The standard behaviour is to send each person an individual email.
dibdab 25-Jan-18 6:23am    
It should be fine because its just within my team..
A_Griffin 25-Jan-18 4:54am    
Have you checked that all the email addresses in the database are valid? Your error message would suggest that maybe some are not (or maybe are just empty strings).
Also, if/when you do get this working, bear in mind that many if not most ISP's provide strict limits on how many emails you can send within certain time periods. You may need to use an email relay service if sending to lots of 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.com");
ds.Rows.Add("email2@domain.com");
ds.Rows.Add("email3@domain.com");

string emailList = ds.Select()
    .Select(r => (string)r["Email"])
    .Aggregate((a, b) => a = a + ";" + b);


in the above emailList will now contain a list of all email addresses separated by semi-colons.
 
Share this answer
 
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.org"));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900