Tuesday, April 24, 2012

C#(Send Email)


public bool SendEmail(string Parameter1, string Parameter2, int Parameter3)
   {

       #region Send

       SmtpClient smtpClient = new SmtpClient();
       MailMessage message = new MailMessage();
       try
       {
           MailAddress fromAddress = new MailAddress(Email);
          
           message.From = fromAddress;//here you can set address
           message.To.Add("youremail@domain.pk");//here you can add multiple to
           message.Subject = "Subject Here";//subject of email
           message.CC.Add("name@domain.com");//ccing the same email to other email address
           //message.Bcc.Add(new MailAddress("name@domain.com"));//here you can add bcc address
           message.IsBodyHtml = true;//To determine email body is html or not

           // ->> Define Email Message With Format<-- 
           message.Body = "<html><body>" +
                       "<table rules='all' style='border-color: #666;' cellpadding=10'>" +
                       "<tr style='background: #eee;'><td colspan='2'><strong>Questions of ' Invitation Request '</strong></td></tr>" +
                       "<tr><td><strong>Email:</strong></td><td>" + Email + "<br/> " +
                       "<tr><td><strong>Subject:</strong></td><td>' Invitation Request '<br/>                                        " +
                       "<tr><td><strong>Location:</strong></td><td>"+ Location +"<br/> " +
                       "<tr><td><strong>Order Per Week:</strong></td><td>" + OrderCount + " " +
                       "</body></html>";
           // -->> End Define Email Message With Format<--
           smtpClient.Send(message);
       }

       catch (Exception ex)
       {
           return false;
       }

       return true;
       #endregion

   }

No comments:

Post a Comment