6

我将每个人的报告动态存储为pdf并且应该将其发送给他们的电子邮件Attacment。如何将其作为电子邮件的附件发送。这是我的代码。

public void Esendmail(string EmailFrom, string EmailTo, 
                      string EmailBody, string EmailSubject, string EmailCC)
{
            MailMessage message = new MailMessage();
            message.From = new MailAddress(EmailFrom);
            message.CC.Add(EmailCC);

            message.To.Add(new MailAddress(EmailTo));
            message.IsBodyHtml = true;
            message.Body = EmailBody;
            message.Subject = EmailSubject;

            SmtpClient client = new SmtpClient();

            client.Send(message);

 }
4

2 回答 2

16

使用此示例代码

MailMessage message = new MailMessage();
message.To = "abc@domain.com";
message.From = "xyz@domain.com";
message.Subject = "mail with pdf";
message.Body = "your pdf attached";
message.Attachments.Add(new Attachment(@"c:\pdftoattach.pdf"));

SmtpMail.SmtpServer = "mail.domain.com";
SmtpMail.Send(message);
于 2012-07-25T05:26:01.590 回答
3
MailMessage message = new MailMessage();
FileStream fileStream = File.Create("PdfPath");
var memoryStream = new MemoryStream();
fileStream.Position = 0;
fileStream.CopyTo(memoryStream);
message.Attachments.Add(new Attachment(memoryStream,Path.GetFileName("PdfPath")));
于 2014-11-25T05:36:48.827 回答