Page 1 of 1

Programatically sending a report by email

Posted: Wed Jan 09, 2008 10:00 am
by Martin Hart Turner
Hello:

Is it possible to programatically send a rendered report by email without showing it on the screen?

I am using a .NET console application and would like to create/render and send the report directly to an email address without user intervention. Is this possible?

TIA,
Martin.

Programatically sending a report by email

Posted: Wed Jan 09, 2008 12:44 pm
by EDV Gradl
You could use

Code: Select all

StiReport MyReport = new StiReport();
// Load Data 
MyReport.RenderReport(false);
MyReport.SaveRendereReport(MyFile);
And now use MyFile and send it with some base .net class

Programatically sending a report by email

Posted: Thu Jan 10, 2008 2:29 am
by Fabio Pagano
I've some experience in this, so i would like to add something to what EDV Gradl said.

In my application i need to send a massive mailing to some recipients (starting from serialized reports) without any kind of user intervention, and a request is that the email has to be stored in the e-mail client of the sender.

If you use a .net class to send the mail, it will not use the e-mail client (eg. Outlook, that's why you have to specify the e-mail provider in the .net class of send mail) so the user will have no trace of the e-mail sent.

To obtain this, after some days of research, i've come out to use the old vb6 mapi ocx through com interop. It uses the default e-mail client.

After that, i've come into another problem coming from Outlook: when you use Outlook through Simple Mapi (that's what the vb6 mapi ocx does) some security messages appears. While you can turn them off through an option in Outlook Express, in Outlook this option is not present. The problem is that my application is distributed to 200 customers here in Italy, so i have no control on their e-mail clients (so i cannot force anyone to use Outlook Express instead of Outlook). To solve the "Outlook messages problem" i've bought for 100 Euros a product that, in your program, can activate and then deactivate the messages (if you want i can give you in private the name of the product, don't know if i can post the name here).

Now i am able to generate several reports, serialize them (i have a spool manager so i have a table where for each report i store the OutputType (Print or E-Mail) and, in the e-mail case, the recipients names and the desired attachment format (pdf, gif, xps, etc.)) and, from the serialized report, i generate massive mailing through any e-mail client.

This is the code i use to generate a single mail (i've omitted the previous code of exporting because EDV gave you already the answer), i've retouched the code to make it pseudo-code, MSMAPI is the interop to vb6 MSMAPI dll:

Code: Select all

Dim MS As New MSMAPI.MAPISession
            If MS.SessionID = 0 Then
                MS.DownLoadMail = False
                MS.LogonUI = True
                MS.SignOn()
            End If

            Dim MM As New MSMAPI.MAPIMessages
            MM.SessionID = MS.SessionID
            MM.Compose()

            'If you have more than one recipient, don't separate with ";" or "," because Outlook 
            'doesn't accept this, use RecipIndex

            MM.RecipIndex = 0

            MM.RecipType = 1 'To

            MM.RecipAddress = TheRecipientAddress

            'Needed for Outlook, this causes the first Outlook Security message
            MM.ResolveName()

            MM.MsgSubject = TheEMailSubject
            MM.MsgNoteText = TheEMailBody

            MM.AttachmentIndex = 0
            MM.AttachmentPathName = AttachmentPath
            
            'This causes the second Outlook security message
            MM.Send(False)

            MS.SignOff()
I've also omitted the deactivation and activation of the Outlook security messages because it uses a third party software.

Let me know if you need any help.

Thanks.

Programatically sending a report by email

Posted: Thu Jan 10, 2008 3:01 am
by Edward
Thank you very much Marco and Fabio (as well as Brendan usually does) for the such good answers!
To solve the "Outlook messages problem" i've bought for 100 Euros a product that, in your program, can activate and then deactivate the messages (if you want i can give you in private the name of the product, don't know if i can post the name here).
Yes, Fabio, please feel free to provide this information on our forum.

Thank you.

Programatically sending a report by email

Posted: Thu Jan 10, 2008 3:31 am
by Fabio Pagano
The "Outlook security messages problem" was solved buying the "Outlook Security Manager" at about 100 Euro from:

http://www.add-in-express.com/outlook-security/

Thanks.

Programatically sending a report by email

Posted: Thu Jan 10, 2008 11:43 am
by Martin Hart Turner
Thanks to all that have replied.

I finally went for the save-to-file (pdf) solution, and then send the generated report as an attachment via the .NET Smtp classes.

Regards,
Martin.