使用SmtpClient将打印文档作为附件发送

时间:2017-06-10 07:50:48

标签: c# winforms email printing smtp

我一直在网上查找使用SMTP在电子邮件中附加打印文档但不幸的是找不到。

printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();

这是我预览文档的代码,我有一个额外的方法可以将所有标签,图像放在纸上。

 private void btnSendEmail_Click(object sender, EventArgs e)
    {
        SmtpClient client = new SmtpClient();
        client.Port = 587;
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true;
        client.Timeout = 10000;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("myUsername@gmail.com", "myPass");

        MailMessage mm = new MailMessage("myRecipents", "myRecipents", "Title", "Body");
        mm.BodyEncoding = UTF8Encoding.UTF8;
        mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

        System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType();
        contentType.MediaType = System.Net.Mime.MediaTypeNames.Application.Octet;
        contentType.Name = "tange.pdf";
        mm.Attachments.Add(new Attachment("C:/tange.pdf", contentType));

        client.Send(mm);

        MessageBox.Show("Success");
    }

这是我发送电子邮件和附加文档的代码。但是这里附带的文件位于我的磁盘中。我想用我的打印文档/预览替换它。

有没有办法做到这一点?

0 个答案:

没有答案