Send reportingservice in the email

Source: Internet
Author: User
Tags smtpclient

1) store the report generation image locally.

 

Code

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

 

 

2) Send the generated image as an inline attachment

 

Code

Email. Body =   " <Div style = \ " Font - Family: Arial \ " > This is an inline attachment: <br/> " @ Image @@\ " Alt = \ " \ " > <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 ();

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.