Saturday, 22 March 2014

How to send email in C#

Send email in 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 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)
                MailMessage objMail = new MailMessage();
                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("");
            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