Send Email Through GoDaddy Server to other Email Account in Asp.net

Suppose in your website you have a contact us or career page in which user may send his data or can contact you and you want that data on y our Gmail, Outlook, Hotmail or other email account. First of all look at the form
In the above form if you want to receive user data on you different email accounts then one thing you should consider in your mind.

 Web browser is not going to directly send data in your email account (email will be send through other email account) , So you will have to give an interface through which your server can send data from client side.

So how you will do it in Asp.net ? for this you will have to go through following steps.

1. add name space
                         using System.Net;
                         using System.Net.Mail;
2. On click event of submit button write following code.
 1. Create an object of MailMessage class like this

         MailMessage msg = new MailMessage(); 
in this object you will get many properties and method to use in sending email

            string email = "Write Here The email ID on which you want to Receive Data";
            string name = "Email ID";
// Now mainmessage string will contain data in prescribe format in which you want
            string mainmessage = "<html><body>Name : " + TextBox1.Text + "<br />" + "Email ID: : " +     TextBox2.Text + "<br />" + "Contact No : " + TextBox3.Text + "<br />" + "Website Name : " + TextBox4.Text + "<br />" +
                "Message : " + TextBox5.Text + "<br /></body></html>";
            MailMessage msg = new MailMessage();
            msg.Subject = "Message or Feedback From a User";
            msg.Body = mainmessage;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;
            msg.From = new MailAddress(TextBox2.Text);
            msg.To.Add(new MailAddress(email.Trim(), name));
            SmtpClient smptc = new SmtpClient(); // Here SMTP Client object is created
            smptc.Host = "smtpout.asia.secureserver.net";// here SMTP interface Address is passed
            smptc.Port = 25;// Use port No 25
            smptc.UseDefaultCredentials = false;
            smptc.EnableSsl = false;
            smptc.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential credentials = new NetworkCredential("Write Email or User name of GoDaddy Email Account", "Password here");
            smptc.Credentials = credentials;
            smptc.Send(msg);
            Response.Write("<script type='text/javascript'>alert('Thanks! for your feedback.')</script>");
            TextBox1.Text = "";
            TextBox2.Text = "";

Hope this would help you.

Similarly you can use Gmail and Hotmail but due to some security reason they do not like such activity.

Comments

Popular posts from this blog

DTS package conversion in SSIS to use in SQL 2012 and SQL 2016

Infinite Scroll in Asp.Net C# using Javascript without Third party Plugin

Add Custom Tags in Web config file in ASP .Net