Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to send email after registration with activation link in asp.net
Posted
Comments
ritika1989 29-Jun-12 4:04am    
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) this problem is coming..
please tell me how to solve

Sending the email is easy - there is a tip here with the code: Sending an Email in C# with or without attachments: generic routine.[^]

All you have to do is use HTML in the email send them a link with parameters:
C#
protected void myCreateUserWizard_CreatedUser(object sender, EventArgs e)
    {
    myCreateUserWizard.LoginCreatedUser = false;
    SMUser user = new SMUser(SMUser.FindByUserName(myCreateUserWizard.UserName));
    Guid registercode = Guid.NewGuid();
    user.VerificationCode = registercode;
    user.Update();
    StringBuilder sb = new StringBuilder();
    sb.AppendFormat("%HTML%#NHi {0}!\n\n   Thank you for registering at MYDOMAIN. To complete your registration, please follow the link below:\n\n", user.UserName);
    string link = string.Format("http://www.MYDOMAIN.com/Register.aspx?RegistrationCode={0}{1}",
                                user.Id.ToString(),
                                registercode.ToString());
    sb.AppendFormat(@"<a href=""{0}"">MYDOMAIN.com Complete Registration</a>", link);
    sb.Append("\n\nWhen you have followed the link, you will be able to log in and use your account.\n");
    sb.Append("If your email system does not allow linking, please copy and paste the following into your browser:\n");
    sb.Append(link);
    sb.Append("\n\n");
    user.SendEmail(sb.ToString());
    myCreateUserWizard.CompleteSuccessText = "Thank you for registering!<br />" +
                                             "An email has been sent to the address you provided.<br />" +
                                             "Please follow the link it gives to complete the process.";
    }

You then read the parameters in the Register.apsx file and mark it finished.
 
Share this answer
 
v3
Check this article up, it is explaining your exact situation.

http://www.4guysfromrolla.com/articles/062508-1.aspx[^]

You can also find a lot of interesting articles on that argument on the same site.


Cheers
 
Share this answer
 
Add a mail definition to your CreateUserWizard:

HTML
<maildefinition bodyfilename="~/Docs/NewUserEmailBody.txt">
            CC="postmaster@mysite.com" From="postmaster@mysite.com"  
            Subject="Welcome to my site"> 
        </maildefinition>


Now, the NewUserEmailBody.txt has your email with <placeholders> for actual values.

<![CDATA[<%NEWUSERID%>]]> is one field. All fields in your email will get replaced automatically and the email will also be sent automatically. You don't need to do anything else except change your ASP code to what I showed you and then write the email with placeholders. Here is the example from mine. Mine does not have an activation page but you can see the other available replacement fields.

Welcome to mysite.

User id: <%UserName%> <br />
Password key: <%Password%> 


"Thanks for your interest in mysite. We welcome you to our family!"

In your activation page, do something like:

C#
protected void Page_Load(object sender, EventArgs e)   
 
{   
 
Guid oGuid = new Guid(Request.QueryString["ID"]);   
 
 //Guid oGuid = new Guid();   
MembershipUser oUser = Membership.GetUser(oGuid);   
if (oUser != null && oUser.IsApproved == false)   
 
 {   
 
oUser.IsApproved = true;   
 
Membership.UpdateUser(oUser);   
 
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(oUser.UserName, false);   
 
}   
 
} 
 
Share this answer
 

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