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

Hi, 
  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

 http://www.asp.net/security/videos/implement-the-registration-verification-pattern

Regards


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-

protected
void SendEmail(object sender, EventArgs e)

{

SmtpClient


smtpClient = new SmtpClient();

MailMessage


message = new MailMessage();

try

{

// Prepare two email addresses

MailAddress


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

MailAddress


toAddress = new MailAddress("ToAddress");

// Prepare the mail message

message.From = fromAddress;

message.To.Add(toAddress);

message.Subject =

"Testing!";

message.Body =

"This is the body of a sample message";

smtpClient.EnableSsl =

true;

smtpClient.Port = 587;

smtpClient.Host =

"smtp.gmail.com";

smtpClient.Credentials =

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

smtpClient.Send(message);

}

catch


(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">
            </MailDefinition>

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
      Try
        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())
        smtp.Send(e.Message)
      Catch ex As Exception
        Response.Write(ex.Message)

      End Try

And here is the web.config :

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

     
    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
    
<system.net>
<mailSettings>
<smtp>
<network host="smtp.gmail.com"
  port="587"
  userName=""
  password=""
</smtp>
</mailSettings>
</system.net>
  
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.To.Add(toEmailAddress);
 
  mail.From = new MailAddress(GmailId);
  mail.Subject = subject;
  mail.Body = bodyMsg;
  mail.IsBodyHtml = true;
 
    SmtpClient smtp = new SmtpClient();
  smtp.EnableSsl = true;
  smtp.Send(mail);
}