Programmatically send e-mail

Stimulsoft Reports.NET discussion
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Programmatically send e-mail

Post by Fabio Pagano »

In the viewer is present a button "Send e-mail", that creates an e-mail with the choosen attachment type. How can i do this by code? Do you expose a method, something like "CreateMailWithPdfAttachment"?

Thanks.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Programmatically send e-mail

Post by Fabio Pagano »

Ok, i think i have found the classes:
Stimulsoft.Report.Export.MAPI
Stimulsoft.Report.Export.MapiMessage
Stimulsoft.Report.Export.MapiFileDesc

but i haven't found how to do this task: i have a serialized report that i need to export as a pdf and then attach it to an email presetting the recipients, the subject and the body, without making appear the email client interface.

I know how to export to pdf, i don't know how to attach the pdf to an email using your MAPI class.

Thanks.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Programmatically send e-mail

Post by Brendan »

Hi Fabio,
Maybe the following thread may be of some help:

http://forum.stimulsoft.com/Default.aspx?g=posts&t=499

User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Programmatically send e-mail

Post by Fabio Pagano »

It doesn't seem to help, because i have to do this programmatically, without viewer and user interaction.

Thanks.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Programmatically send e-mail

Post by Vital »

You can use following way:

1. You need create pdf file for attaching to email message. Use method report.ExportDocument. For example:

Code: Select all

string file = "report.pdf";
report.ExportDocument(file);
2. You need use MailMessage object. For example:

Code: Select all

MailMessage message = new MailMessage();
SmtpMail.SmtpServer = "mail.domain.com";
message.Priority = MailPriority.High;

message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "email@domain.com");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mypassword");

Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
message.Attachments.Add(data);

SmtpMail.Send(message);
You can read more about sending email with attachments at:
http://msdn2.microsoft.com/en-us/librar ... ments.aspx

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Programmatically send e-mail

Post by Fabio Pagano »

Your solution doesn't consider the use of the default email client: i need to save in it the emails sent.

What i wanted to do was to create an email in the default email client, just like you do when in the viewer the user presses "Send email" button, but without opening the email client interface.

To simulate what the viewer does when the user presses "Send email" i could already use the method:

Stimulsoft.Report.Export.MAPI.SendEMail

This method has the following parameters:
"Subject"
"Body"
"FilePath"

I think that this method should have these other parameters:

"Recipient"
"Cc"
"Bcc"
"ShowComposer"

The ShowComposer method instructs if the user interface must appear or not.

The limitation would be that a single file would be allowed as an attachment, just like now (you may think to accept file names separated by ";").

May you do something for this suggestion?

Thanks.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Programmatically send e-mail

Post by Edward »

Sorry, but we can not to enhance ability of our engine in that direction. In that case you should to use the Simple MAPI in your Application. As a base for that you may use use our MAPI class. We can send it for you if necessary.

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Programmatically send e-mail

Post by Fabio Pagano »

Yes, send it to me, thanks.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Programmatically send e-mail

Post by Edward »

The class was sent to the e-mail which was specified by you during the registration on the forum.

Thank you.
User avatar
Fabio Pagano
Posts: 355
Joined: Mon Apr 16, 2007 12:38 pm
Location: Bari (Italy)

Programmatically send e-mail

Post by Fabio Pagano »

Received, thank you.
Post Reply