0

I am using the following code for receiving information from users, is it possible to get all the information as a PDF attachment ?

protected void Button1_Click(object sender, EventArgs e)
    {
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        message.To.Add("admin@domain.com");
        if (CheckBox1.Checked == true)
        {
            emailadd.Text = employeenameDropDown.SelectedValue;

            message.Bcc.Add(emailadd.Text);

        }
        message.Subject = "Timesheet " + employeenameDropDown.SelectedItem;
        message.IsBodyHtml = true;
        message.Body = "<h3>Timesheet</h3>" + System.Environment.NewLine + System.Environment.NewLine + "<br/>";
        message.Body += "<b>Name: </b>" + employeenameDropDown.SelectedItem + "<br/>" + "<br/>";
        smtpClient.EnableSsl = true;
        smtpClient.Send(message);
        EmailSentForm.Visible = Visible;
        employeenameDropDown.Enabled = false;

        Button1.Enabled = false;
    }
1
Contributor
2
Replies
3
Views
5 Years
Discussion Span
Last Post by super123
0

This is what I've done till now, but I cannot open the received PDF file - it says the file might be damaged. Please help me

protected void Button1_Click(object sender, EventArgs e)
    {
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();


         MemoryStream mstream = new MemoryStream();
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.GetInstance(document, mstream);




        message.To.Add("admin@domain.com");
        if (CheckBox1.Checked == true)
        {
            emailadd.Text = employeenameDropDown.SelectedValue;

            message.Bcc.Add(emailadd.Text);

        }
        message.Subject = "Timesheet " + employeenameDropDown.SelectedItem;
        message.IsBodyHtml = true;
        message.Body = "<h3>Timesheet</h3>" + System.Environment.NewLine + System.Environment.NewLine + "<br/>";
        message.Body += "<b>Name: </b>" + employeenameDropDown.SelectedItem + "<br/>" + "<br/>";


        document.Open();
        document.Add(new Paragraph(message.Body));
        message.Attachments.Add(new Attachment(mstream, "time.pdf"));



        smtpClient.EnableSsl = true;
        smtpClient.Send(message);



        document.Close();
        mstream.Flush();
        mstream.Close();



        EmailSentForm.Visible = Visible;
        employeenameDropDown.Enabled = false;

        Button1.Enabled = false;
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.