Sunday, May 5, 2013

Send email in a format c#

    void sndemail()
    {
        MailMessage objEmail = new MailMessage();
        objEmail.To = "xxxxx@xxxxxx.com";//Session["OEMAL"].ToString().Trim();//Emald.ToString().Trim();//txtTo.Text;
        //objEmail.To = "dostind@gmail.com";//Session["OEMAL"].ToString().Trim();//Emald.ToString().Trim();//txtTo.Text;
   
        //objEmail.From = "rajeev@xxxxxx.net";
        objEmail.From = "noreply@xxxxxx.com";

        //objEmail.Cc = txtCc.Text;
        objEmail.Subject = "HI -- Notification";// +Strrslt.ToString();
        //Response.Write(Session["oename"].ToString());  HI Quiz – Course Completion Notification
        //Response.End();
        //objEmail.Body = "<table border=1 bgcolor=#F3EFE0><tr><td>Date :</td><td><b>" + DateTime.Today.ToLongDateString() + "</td></tr><tr><td>Exam Id:</td><td>" + Request["id"].ToString() + "</td></tr><tr><td>Trainee:</td><td> </b> " + Session["repname"].ToString() + "</td></tr><tr><td>Total Correct:</td><td>" + cortans + " Out of:-" + totrec + "</td></tr><tr><td>Owner: </td><td>" + Session["oename"].ToString() + "</td></tr><tr><td>Program:</td><td>Home Impovement</td></tr><tr><td><b>Result:</b></td><td><b>" + Strrslt.ToString() + "</b></td></tr>  </table>";
        objEmail.Body = "<b>The following trainee has completed the Home Improvement training course:</b><br><br>";
        objEmail.Body += "<table border=0 width=50%   bgcolor=#CCCCCC cellpadding=10 ><tr><td>Trainee :</td><td><b>" + Session["repname"].ToString() + "</td></tr><tr><td>Market:</td><td>" + Session["oeMarket"].ToString() + "</td></tr><tr><td>ICD:</td><td> </b> " + Session["owniNam"].ToString().Replace("'"," ") + "</td></tr><tr><td>Date:</td><td>" + DateTime.Today.ToLongDateString() + "</td></tr><tr><td>Total Correct: </td><td>" + cortans + " Out of:-" + totrec + "</td></tr><tr><td><b>Status:</b></td><td><b>" + Strrslt.ToString() + "</b></td></tr>  </table>";
      
        //objEmail.Body = Label4.Text;

        //objEmail.Priority = MailPriority.High;
        objEmail.BodyFormat = MailFormat.Html;//MailFormat.Html; Session["oeMarket"]
        // Make sure you have appropriate replying permissions from your local system

       SmtpMail.SmtpServer = "10.0.10.123";
        //SmtpMail.SmtpServer = "localhost";

        try
        {
            SmtpMail.Send(objEmail);


        }
        catch (Exception exc)
        {
            Response.Write("Send failure: " + exc.ToString());
        }

    }


    private string ConnectionString
    {
        get
        {
            string connectionString = ConfigurationManager.ConnectionStrings["smdbConnectionString51"].ConnectionString;
            return connectionString;
        }
    }

No comments: