Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
My website allow user to create account.

Upon creating, a email verification with a URL will be send to the user's email.

Problem: The sending of email worked but unfortunately the verification URL did not appear.


And for
<a href="<%VerifyUrl%>"<%VerifyUrl%></a></p> 


there is a green curly line beneath "<%VerifyUrl%>", stating that this file could not be found.
File <%VerifyUrl%> was not found


This is the source code of Login.aspx :
XML
protected void CreateUserWizard1_SendingMail(object sender,MailMessageEventArgs e)
{
    MembershipUser userInfo = Membership.GetUser(CreateUserWizard1.UserName);

    //Construct the verification URL
    string VerifyUrl = Request.Url.GetLeftPart(UriPartial.Authority) + Page.ResolveUrl("~/Verify.aspx?ID=" + userInfo.ProviderUserKey.ToString());

   // Replace <%VerifyUrl%> placeholder with verifyUrl value
    e.Message.Body = e.Message.Body.Replace("VerifyUrl", VerifyUrl.ToString());
}


This is the html file that what user would see in their email:
XML
<h2> Welcome to My Website!</h2>
<p>
    Hello, <%UserName%>. You are receiving this email because you recently created a new account at my
    site. Before you can login, however, you need to first visit the following link:</p>
<p>
    <a href="<%VerifyUrl%>"><%VerifyUrl%></a></p>
<p>
    After visiting the above link you can log into the site!</p>
<p>
    If you have any problems verifying your account, please reply to this email to
    get assistance.</p>
<p>
    Thanks!</p>
Posted
Updated 26-Jun-12 6:46am
v2
Comments
Pankaj Nikam 26-Jun-12 12:37pm    
As you mentioned the expected output, can you give us what the user actually gets it?
mathidioticz 26-Jun-12 12:44pm    
All the words inside the html file appeared on the email. Except from the URL
Pankaj Nikam 26-Jun-12 13:04pm    
Have you checked whether the e.Message.Body has a text which has <%VerifyUrl%>?
mathidioticz 26-Jun-12 13:14pm    
what you mean?? sorry, i am new to c#
Pankaj Nikam 27-Jun-12 1:51am    
I meant to say, check whether the property called Body on the Message object which comes with the EventArgs.
Use the code like this: var msg = e.Message.Body;
and use a breakpoint to analyze whether the msg variable has a text called <%VerifyUrl%>.

Please use the reply button to reply this comment as I get notified if you reply. I just happened to check that you have replied, hence the delay. Thanks :)

1 solution

<![CDATA[<% %>]]> are server delimiters. The way you are using it just for the placeholder and then replacing it with some text does not looks like correct implementation.

Refer: Server side Delimiters in ASP.NET[^]

Now, either change the placeholder, keep it like [[....]] OR define VerifyUrl in your code behind such that it can be picked up directly when needed.
 
Share this answer
 
Comments
Pankaj Nikam 26-Jun-12 13:10pm    
Actually I was going to reply in the same manner regarding the server side delimiters but I had a look at http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.createuserwizard.sendingmail.aspx and then realized that its supported. Its strange to find it but it does exist.
Sandeep Mewara 26-Jun-12 14:40pm    
Interesting... thanks for pointing. Will look into it.

Still my answer stands for now.
Pankaj Nikam 27-Jun-12 1:53am    
:) yea definitely... Got a +5 from me :)
mathidioticz 26-Jun-12 13:17pm    
hi, what you mean by keep it like [[....]] ???
Sandeep Mewara 26-Jun-12 14:37pm    
Just changed the placeholder used by you from <%...%> to [[...]]. Presentation or flag to know that something in between double square brackets needs text replacement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900