Programatically sending a report by email
-
- Posts: 66
- Joined: Wed Apr 04, 2007 3:32 am
- Location: Spain
Programatically sending a report by email
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.
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
You could use
And now use MyFile and send it with some base .net class
Code: Select all
StiReport MyReport = new StiReport();
// Load Data
MyReport.RenderReport(false);
MyReport.SaveRendereReport(MyFile);
- Fabio Pagano
- Posts: 355
- Joined: Mon Apr 16, 2007 12:38 pm
- Location: Bari (Italy)
Programatically sending a report by email
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:
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.
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()
Let me know if you need any help.
Thanks.
Programatically sending a report by email
Thank you very much Marco and Fabio (as well as Brendan usually does) for the such good answers!
Thank you.
Yes, Fabio, please feel free to provide this information on our forum.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).
Thank you.
- Fabio Pagano
- Posts: 355
- Joined: Mon Apr 16, 2007 12:38 pm
- Location: Bari (Italy)
Programatically sending a report by email
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.
http://www.add-in-express.com/outlook-security/
Thanks.
-
- Posts: 66
- Joined: Wed Apr 04, 2007 3:32 am
- Location: Spain
Programatically sending a report by email
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.
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.