Sunday, May 15, 2011

Sedning email through serivce(wcf)

Through smtp
==============   USING WCF SERVICE SENDING MAIL

            email.From = new MailAddress("crmprocorp1@gmail.com");
            email.CC.Add("crmprocorp1@gmail.com");
           email.To.Add(txtemail);

         
            float persentage = Convert.ToSingle(examscore) * 100 / 20;

          string str= "<table><tr><td>Congratulations on attaining the following score. Your counselling is scheduled for this Saturday. Please call your</td></tr>";
                   str+=  "<tr><td>Counsellor : Mr.David  at 07799400500 to get your appointment time. Please get a copy of the score card/CV for the counselling.<br/><br/></td></tr>";
                 
                    str+=  "<tr><td>Regards,</td></tr>";
                      str+="<tr><td><b>Anuj T</b></td></tr><br/><br/>";

                      str += "<tr><td><b>Email</b> :anuj@cliniindia.com |<b> Phone</b> :  040 6555 0643  | <b> Website</b> :<a href='www.cliniindia.com'>www.cliniindia.com/info@cliniindia.com</a></td></tr>";
                       str += "<tr><td><b>Address</b> : CLINI INDIA, Swathi Plaza , Raj Bhavan Road ( Near Yashoda Hospital ), Somajiguda , Hyderabad - 500 082</td></tr>";
                       str += "</table>";


            string gradstr = "";
            if (grade == "Grade A")
            {

               // gradstr = "You have scored " + persentage.ToString() + "% for Grade A and secured a schorlarship for RS.30,000 ";
                gradstr = str;
            }
            if (grade == "Grade B")
            {

               // gradstr = "You have scored " + persentage.ToString() + "% for Grade B and secured a schorlarship for RS.20,000 ";
                gradstr = str;
            }
            if (grade == "Grade C")
            {

              //  gradstr = "You have scored " + persentage.ToString() + "% for Grade C and secured a schorlarship for RS.10,000 ";
                gradstr = str;
            }
            if (grade == "sorry")
            {

             //   gradstr = "You have not attended the desired score for the scholarship,You may try again or call our counsellor at 040- 6555 0643.";
                gradstr = str;
                //grade=
            }

            StringBuilder sb1 = new StringBuilder();
            sb1.Append("<html><head><title></title></head><body><table>");
            sb1.Append(" Dear " + txtname + ", <br/><br/> " + gradstr + "<br/><br/>");
            sb1.Append("<tr><td><br/></td></tr><tr><td>");

            sb1.Append("<table>");
            sb1.Append("<tr><td style='background-color:Green' colspan='2'></td></tr>");
            sb1.Append("<tr><td  colspan='2'><h2><b>CliniIndia Exam score card</b></h2></td></tr>");
            sb1.Append("<tr><td><h4><b>Name</b></h4></td><td>" + txtname + "</td></tr>");
            sb1.Append("<tr><td><h4><b>Date of exam</b></h4></td><td>" + DateTime.Now + "</td></tr>");
            sb1.Append("<tr><td><h4><b>Score</b></h4></td><td>" + examscore + " out of 20</td></tr>");
            sb1.Append("<tr><td><h4><b>Percentage</b></h4></td><td>" + persentage + "%</td></tr>");
            //sb1.Append("<tr><td><h4><b>Grade</b></h4></td><td>" + grade + "</td></tr>");
            sb1.Append("<tr><td style='background-color:Green'  colspan='2'></td></tr>");
            sb1.Append("<tr></table>");

              sb1.Append("</td>");
            sb1.Append("</tr></table></body></html>");


            email.Body = sb1.ToString();


            email.Subject = "Scholarship";
            email.IsBodyHtml = true;
            email.Priority = MailPriority.Normal;

            string err = "";

            SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
         
            try
            {
                smtpClient.Send(email);
            }
         
            catch (SmtpFailedRecipientException ex)
            {

                err = ex.Message;
            }
            catch (SmtpException ex)
            {

                err = ex.Message;
            }
            return true;


IN APP.CONFIG
==============

 <!--<smtp from="bhaskar@crmprocorp.com" deliveryMethod="Network">
        <network defaultCredentials="false" enableSsl="false" host="mail.crmprocorp.com" port="25" password="password" userName="bhaskar@crmprocorp.com" />
     
      </smtp>-->
      <smtp from="crmprocorp1@gmail.com" deliveryMethod="Network">
        <network defaultCredentials="false" enableSsl="false" host="smtp.gmail.com" port="587" password="Pu99et@1" userName="crmprocorp1@gmail.com" />
      </smtp>
































No comments:

Post a Comment