2012-07-25 91 views
2

我將每個人的報告動態存儲爲pdf,並將其發送給他們attached with email。我如何將它作爲附件發送到電子郵件。這是我的代碼。如何將pdf文件作爲電子郵件的附件添加到

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); 



} 

回答

9

使用此示例代碼

MailMessage message = new MailMessage(); 
message.To = "[email protected]"; 
message.From = "[email protected]"; 
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); 
0
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"))); 
相關問題