C# .NET - Email replying - Asked By hiren dhameliya on 11-Dec-11 06:32 PM

  Currently I am making a website on book store. I want to put  after resister user  automatic goes email to user email. for example , for  Active account goes into your inbox ....in email cilck in link thant means account active,,,,
I dont know how is put ,,

please reply me as soon as reply me 
Riley K replied to hiren dhameliya on 11-Dec-11 07:42 PM

If you are going to simplicity; then ASP.NET Membership system is the right thing for you.

 There's bunch of videos on how to setup user registration and email confirmation on ASP.NET website:

ASP.NET Membership http://www.asp.net/learn/security-videos/video-389.aspx

Setup email registration confirmation



Jitendra Faye replied to hiren dhameliya on 11-Dec-11 10:50 PM
For this write this email sending code after registration process-

You can send email by using System.Net.Mail Namspace.

Use this code-

void SendEmail(object sender, EventArgs e)



smtpClient = new SmtpClient();


message = new MailMessage();



// Prepare two email addresses


fromAddress = new MailAddress("FromAddress", "DisplayName");


toAddress = new MailAddress("ToAddress");

// Prepare the mail message

message.From = fromAddress;


message.Subject =


message.Body =

"This is the body of a sample message";

smtpClient.EnableSsl =


smtpClient.Port = 587;

smtpClient.Host =


smtpClient.Credentials =

new System.Net.NetworkCredential("UserName", "Password");




(Exception ex)


statusLabel.Text =

"Coudn't send the message!<br />" + ex.Message;



Tre this and let me know.

Anoop S replied to hiren dhameliya on 12-Dec-11 01:27 AM
create a user wizard sendineemail eveny to send a verification email to the newly registered user

This is mail definition in the create user wizard :

 <MailDefinition Priority="High" BodyFileName="~/ConfirmationEmailHTML/ConfirmationEmail.htm">

And here is the code for sending email event :

Public Sub CreateUserWizard1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles CreateUserWizard1.SendingMail
        Dim user As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName.ToString())
        Dim userId As Guid = DirectCast(user.ProviderUserKey, Guid)
        Dim smtp As New SmtpClient()
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network
        smtp.EnableSsl = True
        smtp.Host = "smtp.gmail.com"
        smtp.Port = 587
        smtp.UseDefaultCredentials = False
        smtp.Credentials = New NetworkCredential("xxxx@gmail.com", "mypass")

        e.Message.IsBodyHtml = True
        e.Message.Subject = "Allo Magazine : Registration Confirmation Email"
        e.Message.Body = e.Message.Body.Replace("<%AC%>", userId.ToString())
      Catch ex As Exception

      End Try

And here is the web.config :

    <mailSettings >
    <smtp deliveryMethod="Network" from="ahmad.bastas@gmail.com"   >
      <network   host="smtp.gmail.com"  port="587"  userName="ahmad.hjaj@gmail.com" password="mypass" />

    End Sub
dipa ahuja replied to hiren dhameliya on 12-Dec-11 01:37 AM

At the end of craeting users write the code to send email

Step 1 :
Add this in Web.config
<network host="smtp.gmail.com"
Step 2 : Mail Sending Code
protected void btnSent_Click(object sender, EventArgs e)
  string toEmailAddress = "xx@gmail.com";
  string GmailId = "abc@gmail.com";
  string bodyMsg = "helo its testing mail";
  string subject = "testing mail";
  MailMessage mail = new MailMessage();
  mail.From = new MailAddress(GmailId);
  mail.Subject = subject;
  mail.Body = bodyMsg;
  mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
  smtp.EnableSsl = true;