Feed Icon  

Contact

  • Bryant Likes
  • Send mail to the author(s) E-mail
  • twitter
  • View Bryant Likes's profile on LinkedIn
  • del.icio.us
Get Microsoft Silverlight
by clicking "Install Microsoft Silverlight" you accept the
Silverlight license agreement

Hosting By

Hot Topics

Tags

Open Source Projects

Archives

Ads

CreateUserWizard.SendingMail Event

Posted in ASP.Net/Web Services at Wednesday, December 14, 2005 7:00 AM Pacific Standard Time

This example code from this MSDN page had me stumped for awhile today:

void Createuserwizard1_SendingMail(object sender, MailMessageEventArgs e)
  {
    // Set MailMessage fields.
    e.Message.IsBodyHtml = false;
    e.Message.Subject = "New user on Web site.";
    // Replace placeholder text in message body with information
    // provided by the user.
    e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question);
    e.Message.Body.Replace("<%PasswordAnswer%>",   Createuserwizard1.Answer);
  }

Everytime I signed up a new user it was have <%PasswordQuestion%> and <%PasswordAnswer%> in the body of the message. This totally frustrated me until I that e.Message.Body is just a string and there the Replace method is the standard replace method. Now do you see why it didn't work?

 

Friday, December 16, 2005 9:10:00 AM (Pacific Standard Time, UTC-08:00)
Hmm - the result of Replace seems to be returned to never-never land instead of the body of your email...
Wednesday, January 18, 2006 12:19:00 AM (Pacific Standard Time, UTC-08:00)
If anyone figures this one out, please post. Difficult problem.
bob
Wednesday, January 18, 2006 1:47:00 AM (Pacific Standard Time, UTC-08:00)
The answer to the problem is pointed out in the post, but perhaps it isn't totally clear so I'll post what the above code should be:
<br>
<br>void Createuserwizard1_SendingMail(object sender, MailMessageEventArgs e)
<br> {
<br> // Set MailMessage fields.
<br> e.Message.IsBodyHtml = false;
<br> e.Message.Subject = "New user on Web site.";
<br> // Replace placeholder text in message body with information
<br> // provided by the user.
<br> e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>", Createuserwizard1.Question);
<br> e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>", Createuserwizard1.Answer);
<br> }
<br>
<br>The problem was that the replace method doesn't change the value of the string it is called on. It only returns the result of the replace. So you need to store those results in the body as shown above.
Tuesday, September 05, 2006 9:22:16 AM (Pacific Daylight Time, UTC-07:00)
Thanks! Was having this issue myself today.

As always, so simple when it is pointed out.
Holf
Wednesday, September 05, 2007 4:12:40 AM (Pacific Daylight Time, UTC-07:00)
Holy heck, you just saved me from jumping out a window.

I tried pretty much *everything*. What baffled me was that even though I set a breakpoint, I never saw the code actually touching that bit of code. I tried disabling blocks of my CreateUserWizard ASP markup, and what not.

Thanks a million!

Peter
Comments are closed.