 |
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
|
|
|
|
|

March 7th, 2013, 07:58 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 7th, 2013, 11:29 AM
|
|
Authorized User
|
|
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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.
|
|

March 7th, 2013, 11:53 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 7th, 2013, 12:04 PM
|
|
Authorized User
|
|
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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..
|
|

March 7th, 2013, 05:02 PM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

March 7th, 2013, 05:18 PM
|
|
Authorized User
|
|
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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.
|
|

March 7th, 2013, 05:36 PM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thermopyle, if that is the case then I will try using the help of the book. Thank you!
|
|

March 8th, 2013, 05:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

March 8th, 2013, 11:47 AM
|
|
Authorized User
|
|
Join Date: Jan 2013
Posts: 29
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Quote:
Originally Posted by Imar
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. :)
|
|

March 8th, 2013, 12:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Ah, I missed that. Thanks.
Imar
|
|
 |
|