 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
 | This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
|
|
|
|
|

February 20th, 2009, 01:55 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 15: SendingMail Event
I have reached the section on Sending Confirmation Email with CreateUser Wizard and I am unable to progress because my mail server requires SSL. I have two questions:
1. Why can't I set the EnableSsl property directly?
2. How do I access e.Message of the SendingMail Event? I got a little confused when I read that.
Thank you
|
|

February 21st, 2009, 06:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
1. Why can't I set the EnableSsl property directly?
|
Don't know. Guess you'll need to ask the people at Microsoft who designed this and decided not to make an EnableSsl attriubute for the web.config settings... ;-)
Quote:
2. How do I access e.Message of the SendingMail Event? I got a little confused when I read that.
|
1. Set up a handler for the Sending event. This created a handler with an e argument.
2. Create a new instance of an SmtpClient
3. Set the EnableSsl property to true
4., Send the message:
mySmtpClient.Send(e.Message)
5. Cancel the original message:
e.Cancel = true;
Does this help?
Imar
|
|

February 22nd, 2009, 01:39 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That worked
That seemed to do the trick. Thank you very much for such a quick response. I do however, have one more question. I have understood everything that I have read up to this point, but I don't understand the concept of the e in e.Message or whenever else it is used. Can you please give me a little insight into what e.Message is, or e. in general? Thank you
|
|

February 22nd, 2009, 01:53 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
e is an "EventArgs" class, and contains an object with information relevant to the event being triggered.
The SendingMail event id triggered by code inside ASP.NET. Just before it fires the event it creates an EventArgs object and attached relevant information to it, in this case to the Message property. That allows you to make changes to the message before it gets eventually sent. The internal ASP.NET code looks somewhat like this pseudo code:
1. MailMessage myMessage = new MailMessage();
2. // Set To, subject, Body whatever here. Skipped
3. // Fire the SendingMail event
4. MailMessageEventArgs e = new MailMessageEventArgs()
5. e.Message = myMessage;
6. OnSendingMail(this, e);
7. if (!e.Cancel == true)
8. new SmtpClient.Send(myMessage);
So, between step 6 and 7 your event handler fires. You can look at the message through the e argument and make any changes if you want. Then, if you don't set e.Cancel to true, the rest of the code fires and the message is sent.
Does this help?
Imar
|
|

February 22nd, 2009, 02:05 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That clears up a lot, thank you. But I am afraid that I have run into the same SSL error with the password reset page. There is no mail sending for the password recovery to set the ssl property. What am I missing?
|
|

February 22nd, 2009, 02:49 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
??? Are you saying there is no SendingMail event on the PasswordRecovery class? There is one on my machine....
http://msdn.microsoft.com/en-us/libr...ndingmail.aspx
Imar
|
|

February 22nd, 2009, 03:09 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No. There is no lightning bolt or anything. I double checked with the source code file that I downloaded to make sure that I had no errors, but it is not available when I load that page either. This is the code for the page that I have.
<%@PageLanguage="VB"MasterPageFile="~/MasterPages/MasterPage.master"AutoEventWireup="false"CodeFile="Login.aspx.vb"Inherits="Login"title="Log in to Planet Wrox" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="cpMainContent"Runat="Server">
<asp:LoginViewID="LoginView1"runat="server">
<LoggedInTemplate>
You are already logged in
</LoggedInTemplate>
<AnonymousTemplate>
<asp:LoginID="Login1"runat="server"CreateUserText="Sign Up for a New Account at Planet Wrox Now"CreateUserUrl="SignUp.aspx">
</asp:Login>
<br/><br/>
<asp:PasswordRecoveryID="PasswordRecovery1"runat="server">
<MailDefinitionsubject="Your New Password"></MailDefinition>
</asp:PasswordRecovery>
</AnonymousTemplate>
</asp:LoginView>
<asp:LoginStatusID="LoginStatus1"runat="server"/>
</asp:Content>
|
|

February 22nd, 2009, 03:13 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Make sure your page is valid, and that you are in Design View. As the MSDN article shows you there is definitely a SendingMail event for the Password recovery.
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server" OnSendingMail="PasswordRecovery1_SendingMail">
<MailDefinition Subject="Your New Password for PlanetWrox.Com"></MailDefinition>
</asp:PasswordRecovery>
Code behind:
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
// Your code here
}
Cheers,
Imar
|
|

February 22nd, 2009, 03:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Or in VB:
Protected Sub PasswordRecovery1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs)
End Sub
Imar
|
|

February 22nd, 2009, 03:25 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you!
Thank you very much for yet another quick reply. It works perfectly now and I am able to move on without feeling utterly clueless. Thanks again.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| chapter 15 - |
ciwluke |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
0 |
July 11th, 2008 03:33 PM |
| chapter 15 help |
kyledonmoyer |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
2 |
June 30th, 2007 08:06 AM |
| chapter 15 |
manal_sag |
BOOK: Beginning ASP 3.0 |
2 |
March 13th, 2006 04:48 PM |
| chapter 15 |
manal_sag |
BOOK: Beginning ASP 3.0 |
0 |
April 22nd, 2005 02:23 PM |
| Chapter 15!! |
studentinpain |
BOOK: Beginning ASP 3.0 |
16 |
March 12th, 2004 10:26 AM |
|
 |