Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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 May 17th, 2013, 11:55 AM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Lightbulb Passing variable for User Name when sending email

Chapter 9 includes examples to send email. In these examples User Name hard coded in the web.config file in the <system.net> element:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="Your Name @lt;[email protected]@gt;"> <network host="smtp.yourprovider.com" />
</smtp>
</mailsettings>
</system.net>

Is it posible to modify this example not include the address of SMTP server globally in the web.config, instead include it inside web page and make User Name as variable to let it be dymamically changed depends on who currently login to the website? For example when User Name extracted for the current user from Active Directory?
 
Old May 18th, 2013, 07:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The from attribute in the web.config only serves as a default / fallback for cases where you don't specify one in code. Take a look at the example on page 319 and you'll see something like this:

Code:
myMessage.From = New MailAddress("[email protected]", "Sender Name")
Replace the name and address with your own data to make this dynamic.

Not sure why you would want to change the SMTP server (used to send the messages) based on the user, but you can do it by specifying an alternative server when constructing the SmtpClient:

Code:
Dim mySmtpClient As SmtpClient = New SmtpClient("your.host.here")
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 May 21st, 2013, 11:38 AM
bpl bpl is offline
Authorized User
 
Join Date: May 2009
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you Imar. I did not pay attention that user name from code on page 319 can override user name from web.config. Of course, SMTP Server address from web.config I am not going to change.





Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control Email Sending papimann ASP.NET 4 General Discussion 7 March 5th, 2011 06:17 AM
Sending an Email to the user causes the error - [SqlException (0x80131904) Paul Carter BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 November 19th, 2009 06:53 AM
Sending Email drjohnnygills BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 August 13th, 2009 05:09 AM
Sending EMAIL charleshua BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 16 September 3rd, 2008 12:27 AM
Passing variable to a public variable Hudson40 Access VBA 2 February 25th, 2005 06:23 AM





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