Attach document in mail with c #

0

Is there a way to attach a document previously created by iText?

Currently I have a button that is "Generate offer", create the document by itext, and if you have an activated checkbox it asks if you want to send it by email and opens the mail app. The thing is to attach the document created by itext that you have created.

This is what I have:

            if (check_enviaremail.Checked == true)
        {
            var result = MessageBox.Show("¿Quieres enviarla por email?", "Atreus - Informacion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                System.Diagnostics.Process.Start("mailto:" + tb_email.Text + "");
            }
        }
    
asked by S.Carrillo 10.09.2018 в 12:34
source

1 answer

3

Did you try to do something like that?

PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);

// Aquí construis tu PDF

writer.CloseStream = false;
doc.Close();

// Construis el e-mail

memoryStream.Position = 0;
mm.Attachments.Add(new Attachment(memoryStream, "test.pdf"));

This answer is based on brianng in StackOverflow in English.

On the other hand, I recommend you use System. Net.Mail and System.Net .Mail.Attachment instead of mailto for sending e-mail with attachments.

Greetings!

    
answered by 10.09.2018 в 13:28