Sunday, 21 July 2019

Send email using Godaddy asp.net c# from gmail account

///////////////////////
                         ///////////////////  Godaddy

public static void Email_Send_Godady(string Htmlbody, string mSubject)
{
  try
   {
       string[] Credentials = { "Yourmail@gmail.com", "password" };

       MailMessage msgs = new MailMessage();
       msgs.To.Add("ToEmail id");
       msgs.From = new MailAddress(Credentials[0], "Sender Name"); ;
       msgs.Subject = mSubject;
       msgs.Body = Htmlbody;
       msgs.IsBodyHtml = true;
       SmtpClient client = new SmtpClient();
       client.Credentials = new System.Net.NetworkCredential(Credentials[0], Credentials[1]);
       client.Host = "relay-hosting.secureserver.net";
       client.Port = 25;
       client.EnableSsl = false;
       client.UseDefaultCredentials = false;
       client.Send(msgs);
    }
    catch (Exception ex)
    {
       string msg = ex.ToString();
    }

}


                                    ///////////////////  Gmail


public static void Email_Send_Godady(string Htmlbody, string mSubject)
{
  try
   {
       string[] Credentials = { "Yourmail@gmail.com""password" };

       MailMessage msgs = new MailMessage();
       msgs.To.Add("ToEmail id");
       msgs.From = new MailAddress(Credentials[0], "Sender Name"); ;
       msgs.Subject = mSubject;
       msgs.Body = Htmlbody;
       msgs.IsBodyHtml = true;
       SmtpClient client = new SmtpClient();
       client.Credentials = new System.Net.NetworkCredential(Credentials[0], Credentials[1]);
       client.Host = "smtp.gmail.com";
       client.Port = 587;
       client.EnableSsl = true;
       client.UseDefaultCredentials = false;
       client.Send(msgs);
    }
    catch (Exception ex)
    {
       string msg = ex.ToString();
    }



}

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...