Click here to Skip to main content
15,891,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want to send pdf file to outlook

i am getting error

The remote certificate is invalid according to the validation procedure c#


C#
protected void ExportToPDF(object sender, EventArgs e)
{
    using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            {
                DetailsView1.RenderControl(hw);
                StringReader sr = new StringReader(sw.ToString());
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    PdfWriter.GetInstance(pdfDoc, memoryStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    byte[] bytes = memoryStream.ToArray();
                    memoryStream.Close();
                    string too = string.Concat(DropDownList1.SelectedValue, "@med.sa");
                    string from1 = String.Concat(Label1.Text, "@med.sa");
                    string pass = Session["Pass"].ToString();
                    MailMessage mm = new MailMessage(from1,too);
                   mm.Subject = "GridView Exported PDF";
                 mm.Body = "GridView Exported PDF Attachment";
                   mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "GridViewPDF.pdf"));
                mm.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "100.43.100.101";
                smtp.EnableSsl = true;
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName = from1;
                NetworkCred.Password = pass;
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 30;
                smtp.Send(mm);
    }
}
Posted

1 solution

 
Share this answer
 
Comments
$ultaNn 20-Jan-14 4:17am    
i can convert gridview to pdf . i want to send that pdf in email i am getting error

The remote certificate is invalid according to the validation procedure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900