0

In visual studio 2008, asp.net / vb.net, I want to be able to generate an mhtml Report Server report, then read it into the body of an email message, and send the email.

I know how to initiate the report, and how to generate/send the email message.

What I'm confused about, is how to 1) retrieve the report, and 2) load the report into an email "body variable."

The report is returned as a link.

An example would be great.

Thanks,
Randy

3
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by blackbr
0

Hi,
You can do it using CDO.Message
You can generate the report in a seperate file and call the file in CreateMHTMLBody() method.

Here is an example

CDO.Message msg=new CDO.Message()
msg.to= toaddress
msg.cc=
msg.from= fromaddress
msg.subject= msg.CreateMHTMLBody(reportpageurl,CDO.CdoMHTMLFlags.cdoSuppressNone,"","");
msg.send()

0

Use the ReportingService Class which contains the methods and properties that can be used to call the Reporting Services Web service.

Using the Render method, you can generate the report as mhtml content.

Assign this mhtml content in the Body of a MailMessage class in asp.net. You need to set IsBodyHtml property to true. Also send it as an e-mail using SmtpClient class.

0

Praveenkumarm,
This looks good.... but how do I dim the msg variable in vb?
There is no "cdo.message" object type available, so I can't instantiate it.
Do I need to include additional libraries?

Thanks,
Randy

0

I added the CDO service.
the following is the code...

Dim myMail As New CDO.Message
			myMail = CreateObject("CDO.Message") '[is this necessary?]
			myMail.Subject = subject
			myMail.From = EmailFrom
			myMail.To = EmailTo
			myMail.CreateMHTMLBody("http://xxx.xxx.xxx.xxx/ReportServer?/AdHocReports/WelcomeLetter&rs:Command=Render&rs:Format=MHTML&LeadID=45250", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")
			myMail.Send()
			myMail = Nothing

I am getting the following CDO error...
------
The content type was not valid in this context. For example, the root of an MHTML message must be an HTML document.

stack trace...
CDO.IMessage.CreateMHTMLBody(String URL, CdoMHTMLFlags Flags, String UserName, String Password) +0

Edited by Ezzaral: Added [code] [/code] tags. Please use them to format any code that you post.

0

Yes you need to iport a namespace

But CDO object model is used to send mails from classic ASP application which is obsolete in ASP.NET.

Microsoft recommends to use System.Net.Mail namespace and related classes to send mail.

0

How would the code change with the System.Net.Mail namespace?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.