Posted 14 September 2017, 9:45 am EST
[activereports_archive]Hello,
Is there a way to send the rendered report to e-mail,
Thanks,
Jai[/activereports_archive]
Forums Home / ActiveReports / ActiveReports v7+
Posted by: kmitsupport on 14 September 2017, 9:45 am EST
Posted 14 September 2017, 9:45 am EST
[activereports_archive]Hello,
Is there a way to send the rendered report to e-mail,
Thanks,
Jai[/activereports_archive]
Posted 14 September 2017, 9:45 am EST
[activereports_archive]Jai,
If you are looking to send a report via E-Mail then you can export it to the desired format (say PDF) and send it as an attachment. To do this, you can use the System.Net.Mail namespace:
http://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx
The sample code will be like this:
private void btnSendAsEmail_Click(object sender, EventArgs e) { NewActiveReport1 rpt = new NewActiveReport1(); //Initialize a Memory Stream System.IO.MemoryStream memStream = new System.IO.MemoryStream(); //Export the report to a Memory Stream pdfExport1.Export(rpt.Document, memStream); //Set the postion of Memory Stream to 0 memStream.Position = 0; //Create a new Message MailMessage message = new MailMessage(); //Create an Attachment object. Attachment attach = new Attachment(memStream, "sample.pdf"); //Set the TO Email Address message.To.Add(new MailAddress("Receiver's E-mail address")); //Set the FROM Email Address message.From = new MailAddress("Sender's E-mail address"); //Set the Subject of the Message message.Subject = "test"; //Add the attachment to the Message message.Attachments.Add(attach); //Create an SMTPClient SmtpClient client = new SmtpClient("ServerName"); //Send the Message client.Send(message); this.lblName.Text = "Your E-mail has been sent"; }
You will need to set the sender’s E-Mail, receiver’s E-Mail and the SmtpClient name to get it working. Also you may want to check the following link to know more about its usage in web applications:
http://weblogs.asp.net/scottgu/432854
Attached is a sample application which demonstrates this implementation.[/activereports_archive]
2014/08/SendReportAsEmail.zip
Posted 14 September 2017, 9:45 am EST
[activereports_archive]This is close, but I want to put my report in the body of the email. I am using 8.3.364 of grapecity active reports. My app is a winforms app. My report is a short one page report.
[/activereports_archive]
Posted 14 September 2017, 9:45 am EST
[activereports_archive]Jim,
I think you can achieve the desired results by exporting the report to HTML and then using MailMessage class send the HTML as E-Mail body. Here are some links which should give you some idea about how to approach this implementation:
http://stackoverflow.com/questions/1155797/send-a-email-with-a-html-file-as-body-c
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage(v=vs.110).aspx
Also check out the following documentation link to know more about exporting a report to HTML:
http://helpcentral.componentone.com/netHelp/AR9/HTML.html
Regards,
Sankalp[/activereports_archive]