How to send email from asp.net 2.0 applications using System.Net.Mail in c# Print

  • 1

 





using

System.Net.Mail;

 

    public

static bool

SendAnEmail(string ToEmail, string FromEmail, string

SubjectText, string BodyText)

    {

        try

        {

          

SmtpClient client = new

//Note: get the mail server settings in your EDTHosting.com control panel account under the my email icon

SmtpClient("mailXYZ.empiredatatech.com");

          

MailMessage msgMail = new MailMessage();

          

msgMail.IsBodyHtml = true;

 

          

msgMail.Subject = SubjectText;

          

msgMail.To.Add(ToEmail);

          

msgMail.From = new MailAddress(FromEmail);

 

          

msgMail.Body = BodyText;

 

          

client.Send(msgMail);

 

          

return true;

        }

        catch (Exception)

        {

 

          

return false;

        }

 

  

}

 


Was this answer helpful?

« Back