Sending a registration complete email from asp.net application using c#


in your web application / website, you may wish to send a confirmation email to the user the moment he registers into your website. This so simple. I’ve illustrated the following 3 steps, which completely defines it

Step – 1
—————–
Include the following libraries

using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;

Step – 2
—————–
Add the following into the web.config file just above the “<system.webServer>” tag

<system.net>

<mailSettings>

<smtp from="info@walletchange.com">

<network host="mail.2lessons.com" port="25"
userName="info@2lessons.com"
password="Your Password" />

</smtp>

</mailSettings></system.net>

Step – 3
——————
Add the following code into your registration page code behind (c#)

MailMessage message = new MailMessage();
message.From = new MailAddress("info@2lessons.com");
message.To.Add(new MailAddress("admin@2lessons.com"));
message.CC.Add(new MailAddress("webmaster@2lessons.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);

20 thoughts on “Sending a registration complete email from asp.net application using c#

  1. Collect the email address (From the user registration page)

    e.g. UserEmail = rahul@yahoo.com
    Then add the following into the code

    MailMessage message = new MailMessage();

    message.From = new MailAddress(“info@companyname.com”);
    message.To.Add(new MailAddress(UserEmail));

    message.Subject = “Welcome to itswadesh.wordpress.com”;
    message.Body = “Congratulations !!! Now you have all the rights of a user”;
    SmtpClient client = new SmtpClient();
    client.Send(message);

  2. Dear Sir
    when i use this code then show like this error
    “Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.”
    and my code is
    MailMessage message = new MailMessage();
    message.From = new MailAddress(“webmaster@programmingfunda.in”);
    message.To.Add(new MailAddress(“sheelu.pandit@gmail.com”));
    //message.CC.Add(new MailAddress(“”));
    message.Subject = “This is my subject”;
    message.Body = “This is the content”;
    SmtpClient client = new SmtpClient();
    client.Send(message);

  3. and when i send a mail to webmaster@programmingfunda.in
    using above code then msg send no error show
    if i wrote this code like this then no error show
    “message.From = new MailAddress(“sheelu.pandit@gmail.com”);
    message.To.Add(new MailAddress(“webmaster@programmingfunda.in”));”
    then mail is send to webmaster mail id
    but i want to send mail to sheelu.pandit mail id how can do
    sir pls help me

  4. Dear Rahul,
    Sorry for late reply.

    I’ve tried both yahoo and gmail, and the above code works fine.
    May be you could check, whether your code contains the following set of libraries

    using System.Net;
    using System.Net.Mail;
    using System.Net.Mime;
    using System.Threading;
    using System.ComponentModel;

  5. i want to send link for the confirmation in the message body and if the user clicks on the link then only he should be allowed to login..

  6. hi sir
    i use above coding but error msg for Failure sending mail.
    why sir any idea..
    my mail setting

    ——
    my .cs

    protected void Send_Mail_1()
    {
    MailMessage msg = new MailMessage();
    msg.From = new MailAddress(“xxx@deexplorer.com”);
    msg.To.Add(new MailAddress(“rkthiyaku1987@hotmail.com”));
    msg.CC.Add(new MailAddress(“xxx@deexplorer.com”));
    msg.Subject = “Test Mag”;
    msg.Body = “hi! This is thiyaku”;
    SmtpClient client = new SmtpClient();
    try
    {
    client.Send(msg);
    lblMessage.Visible = true;
    lblMessage.Text = “Successfully Sent Mail!”;
    }
    catch (Exception ex)
    {
    lblMessage.Visible = true;
    lblMessage.Text = ex.Message.ToString().Trim();
    }

    }
    ———–
    please reply as my mail as soon as fast please……
    my mail Id:-rkthiyaku1987@deexplorer.com

  7. My Config For:

    -system.net-
    -mailSettings-
    -smtp from=”XXXXXXX@deexplorer.com”>
    <network host="mail.deexplorer.com" port="12" userName="XXXXXXXX@deexplorer.com" password="******" –
    -smtp-
    -mailSettings-
    –system.net-
    but i get same error..
    i am alraey send above part

    tag not support for this–

  8. Hey sir.Your code is just send an email with a normal text.But I need send a confirmation link and after a user clicks this url make some job.Can you help me?

  9. i need send a confirmation link after this user click on that link to activate the account…
    My code like this bt it shows error…
    ***********************************************
    MailMessage mm = new MailMessage(“xyz@sify.com”,txteml.Text,”Activation Link From Website”,”You can activate your account by clicking below link” http://Localhost/My_Project_1/frmact.aspx?rcod=“+a.ToString());
    SmtpClient c=new SmtpClient(“Mail.connectzone.in”,25);
    c.Send (mm);
    Label1.Text=”Registration sucessful. Activation Mail has been sent to your E-mail account”;

  10. if (ds.Tables[0].Rows.Count > 0)
    {
    MailMessage loginInfo = new MailMessage();
    loginInfo.To.Add(emailid.Text.ToString());
    loginInfo.From = new MailAddress(“supr.priya@gmail.com”);
    loginInfo.Subject = “Forgot Password Information”;

    loginInfo.Body = “txtusername: ” + ds.Tables[0].Rows[0][“txtusername”] + ” Password: ” + ds.Tables[0].Rows[0][“txtpassword”] + “”;

    loginInfo.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Credentials = new System.Net.NetworkCredential(“supr.priya@gmailo.com”, “***********”);
    smtp.EnableSsl = true;
    smtp.Send(loginInfo);
    emailid.Text = “”;
    }
    sir i write like this but i got a errorobject reference not set to an instance of an object please clear the error

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s