我正在尝试将从 ReportViewer 控件生成的 PDF 附加到 Outlook 电子邮件。我有 Office 2013。
当我尝试它时,会发生以下情况(例外:“对不起,出了点问题。您可能想再试一次。”有什么想法吗?
private void btnEmail_Click(object sender, EventArgs e)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes = reportViewer1.LocalReport.Render(
"PDF", null, out mimeType, out encoding, out filenameExtension,
out streamids, out warnings);
using (FileStream fs = new FileStream("Confirmation Letter.pdf", FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
School school = School.FromID(Convert.ToInt32(booking.School));
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = SystemData.SystemInformation.GetValue("LetterSubject");
mailItem.To = school.MainEmail;
mailItem.Body = SystemData.SystemInformation.GetValue("LetterMessage");
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
Attachment att = new Attachment(new MemoryStream(bytes), "Confirmation Letter.pdf");
mailItem.Attachments.Add(att);
mailItem.Display(true);
}
}