Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2013, 07:58 AM
Registered User
 
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending Email multiple users of database

Hi all,

I have been working through the book to create my website. Having sent an single email as shown, I need to send an email to multiple users of my SQL Server database.

Is there a recomended way of doing this as I cannot find any solutions from the book and am struggling to find anything online.

I am using a slightly modified ASPNET.MDF database (additional employee details and safety details table)

I don't think I will have anymore than 50 users.

Any help would be much appreciated, thank you!

Please feel free to ask any questions should you need!

Phil
 
Old March 7th, 2013, 11:29 AM
Authorized User
 
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
Default

How are you going to determine which users to email? If there's a particular query you can run against the database to get the list, you could use that as a way to generate the list, then add each address accordingly as to, cc, or bcc on the email.
 
Old March 7th, 2013, 11:53 AM
Registered User
 
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The email will be sent to all members of the site (all in the same table). So realistically if I could create a query and address each accordingly that would work.

Do you know the best way for approaching this/code would be?

Thank you for your reply
 
Old March 7th, 2013, 12:04 PM
Authorized User
 
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
Default

I would do something like this in the block that you're generating the email in, with assumptions about your database layout (.Users and p.Email would need to be changed to whatever you're using):

using (PlanetWroxEntities myEntities = new PlanetWroxEntities())
{
List<string> emailAddresses = (from p in myEntities.Users
select p.Email);
}
foreach (string emailAddress in emailAddresses)
myMessage.To.Add(new MailAddress(AppConfiguration.ToAddress, emailAddress));

This is not tested, and I'm unsure of the syntax of the List<string> line, but you should get the idea.

Last edited by Thermopyle; March 7th, 2013 at 12:07 PM..
 
Old March 7th, 2013, 05:02 PM
Registered User
 
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I feel this might be pushing it, but would you know of any tutorials online I could follow for this. I am recently new to ASP.NET and I think the below is slighly over my head. Appreciate your help!
 
Old March 7th, 2013, 05:18 PM
Authorized User
 
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
Default

The code I provided is actually (aside possibly from the foreach loop) quite standard by the time you get to the end of the book. Rather than running around looking for resources to answer a specific question you have, I'd recommend working through the rest of the book to get a better foundation on the basic concepts. Once you've got that, you'll have a better understanding of how to approach the site design in general and better knowledge of what to look for when you run into specific issues like the one you're asking about. I know that when I've tried to do research into how to do things that I didn't have a basic programming background in, I often would find convoluted answers that were difficult to implement because of my lack of knowledge leading to asking the wrong questions. A good foundation makes a big difference in how easy it is to resolve problems in programming, I think.
 
Old March 7th, 2013, 05:36 PM
Registered User
 
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thermopyle, if that is the case then I will try using the help of the book. Thank you!
 
Old March 8th, 2013, 05:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

One note on the code from Thermopyle:

Code:
foreach (string emailAddress in emailAddresses)
        myMessage.To.Add(new MailAddress(AppConfiguration.ToAddress, emailAddress));
This adds the e-mail address of all people in the list to the To field of a single e-mail message. This means everyone can see all recipients. You probably don't want this. You can add your own own address to the To and then add all recipients to the Bcc field, or you can send out individual messages within the loop, each one addresses to a single user from the list of addresses.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 8th, 2013, 11:47 AM
Authorized User
 
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by Imar View Post
One note on the code from Thermopyle:

Code:
foreach (string emailAddress in emailAddresses)
        myMessage.To.Add(new MailAddress(AppConfiguration.ToAddress, emailAddress));
This adds the e-mail address of all people in the list to the To field of a single e-mail message. This means everyone can see all recipients. You probably don't want this. You can add your own own address to the To and then add all recipients to the Bcc field, or you can send out individual messages within the loop, each one addresses to a single user from the list of addresses.

Hope this helps,

Imar
I did address this earlier by saying "If there's a particular query you can run against the database to get the list, you could use that as a way to generate the list, then add each address accordingly as to, cc, or bcc on the email." I should have been explicit in the code example post that it would do that, however. :)
 
Old March 8th, 2013, 12:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, I missed that. Thanks.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending One Single Email for multiple radio button selections danhwright ASP.NET 4 General Discussion 2 March 24th, 2011 11:53 AM
sending emails for all users in the domain arabuafef ASP.NET 1.0 and 1.1 Basics 6 December 6th, 2006 10:51 AM
Pulling a Users Email from AD or Exchange Zeus_Man General .NET 0 September 14th, 2006 09:33 AM
Email to todays Birthday users t400 SQL Server 2000 2 September 6th, 2006 08:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.