1)先将报表生成图片存储于本地
代码
string deviceInfo = "<DeviceInfo><OutPutFormat>PNG</OutPutFormat></DeviceInfo>";
string format="image";
byte[] bytes = ReportView1.ServerReport.Render(format,deviceInfo,out mimeType,out encoding,out fileNameExtension,out streamids,out warnings);
FileStream fs = new FileStream("hi.png",FileMode.Creat);
fs.Write(bytes,0,bytes.Length);
fs.Close();
string format="image";
byte[] bytes = ReportView1.ServerReport.Render(format,deviceInfo,out mimeType,out encoding,out fileNameExtension,out streamids,out warnings);
FileStream fs = new FileStream("hi.png",FileMode.Creat);
fs.Write(bytes,0,bytes.Length);
fs.Close();
2)将生成的图片作为内联附件发送
代码
email.Body = "<div style=\"font-family:Arial\">This is an INLINE attachment:<br /><br /><img src=\"@@IMAGE@@\" alt=\"\"><br /><br />Thanks for downloading this example.</div>";
// generate the contentID string using the datetime
string contentID = Path.GetFileName(attachmentPath).Replace(".", "") + "@zofm";
// create the INLINE attachment
string attachmentPath = Environment.CurrentDirectory + @"\test.png";
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentId = contentID;
inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);
email.Attachments.Add(inline);
// replace the tag with the correct content ID
email.Body = email.Body.Replace("@@IMAGE@@", "cid:" + contentID);
SmtpClient smtp = new SmtpClient("localhost");
smtp.Send(email);
email.Dispose();
// generate the contentID string using the datetime
string contentID = Path.GetFileName(attachmentPath).Replace(".", "") + "@zofm";
// create the INLINE attachment
string attachmentPath = Environment.CurrentDirectory + @"\test.png";
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentId = contentID;
inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);
email.Attachments.Add(inline);
// replace the tag with the correct content ID
email.Body = email.Body.Replace("@@IMAGE@@", "cid:" + contentID);
SmtpClient smtp = new SmtpClient("localhost");
smtp.Send(email);
email.Dispose();