Showing posts with label send mail. Show all posts
Showing posts with label send mail. Show all posts

Tuesday, June 10, 2014

How to send mail from GoDaddy server in ASP.NET C#


I found some errors in sending mail from a GoDaddy server, and after searching a lot I found the correct solution to send mail.

First add these namespaces in your project





using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.Net.Mail;

Now the send mail method is



public void Send_User_Confirmation_Mail()
{
    MailMessage mail = new MailMessage();
    mail.To.Add("<email to send>");
    mail.From = new MailAddress("<send mail>");
 
    mail.Subject = "Account Created.";
          
    string Body = "<body>";
 
    mail.Body = Body;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "relay-hosting.secureserver.net";
    smtp.EnableSsl = true;
    smtp.Credentials =  
      new System.Net.NetworkCredential("<send email>"), "<send password>");
    ServicePointManager.ServerCertificateValidationCallback =  
      delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
      { return true; };
    smtp.Port = 25;
    smtp.Send(mail);
}

These are main things to add with your normal mail sending code.



smtp.Host = "relay-hosting.secureserver.net";
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Send_Mail_From_Email"].ToString(), ConfigurationManager.AppSettings["Send_Mail_From_Password"].ToString());
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
smtp.Port = 25;

Before adding there 3rd line of credential I was getting error of some invalid certificate issue to send a mail. But adding these all the issue become normal and mail is sending without any problem.

Monday, January 20, 2014

How to send mail using C# in ASP.NET

Mail sending is a vital thing in web technology. In ASP.NET you have to follow a very few steps to send a mail from your email id to others. So how to send mail using C# in ASP.NET. Lets have a look..

You need to take help of two new classes. 
and a namespace has to be imported. 
  • using System.Net.Mail;
So lets check the code here.

Popular Posts

Pageviews