Saturday, 22 March 2014

How to send email in asp.net C#

Send email in asp.net C# the mail is the common in this days even you are registering any subscription or any promotion. Each and every time you need to send the mail.  Its very easy using below C# code  to send the mail from asp.net through c# code. you should have the SMTP configured server to sending the mail to the server.

  Code Snippet

@C# code; You need to import the mail name space into your application to work with Mailmessage class

using System.Net.Mail;




Copy and paste the below code snippet where you are sending the mail as the HTML format

protected void SendMail(string mailTo, string mailFrom, string mailSubject, string mailBody)
        {
            try
            {
                MailMessage objMail = new MailMessage();
                objMail.To.Add(mailTo);
                objMail.From = new MailAddress(mailFrom);
                objMail.Subject = mailSubject;
                mailBody = mailBody + "<br /> <br /> <br /> It is autogenerated mail Please don't replay on this mail id ";
                objMail.Body = mailBody;
                objMail.IsBodyHtml = true;
                objMail.Priority = MailPriority.High;
                SmtpClient mount = new SmtpClient("smtp.xxxxx.com");
                mount.Send(objMail);
            }
            catch (Exception ex) { }
        }
  Call that method and enjoy sending the mails to the any one.

SendMail(mailto,mailfrom,mailsubject,mailbody)  [ENJOY]

No comments:

Post a Comment

Others

You will like to read it