Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

19.07 Exporting to Email

Exporting to Email

Exporting a report to an email creates the report as a separate file and attaches it to an email message. This email message is automatically sent out to the recipient. Table 19-5 shows the properties for exporting to email. Each of these properties relates to the typical settings you find when sending an email message.

Table 19-5. MicrosoftMailDestinationOptions Properties.

Property Description
MailCCList The list of emails to send a carbon copy to
MailMessage The text portion of the email message
MailSubject The text subject heading of the email message
MailToList The email(s) of those receiving the report
Password The password used when logging on to the email account
UserName The user name used when logging on to the email account

Listing 19-3. Send a report as an attachment of an email.
Public Sub SetEmailDestination(ByVal MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal MailTo As String, ByVal CCList As String, ByVal Subject As String, ByVal Message As String, ByVal UserName As String, ByVal Password As String)
'Set the destination type to EMail
MyReport.ExportOptions.ExportDestinationType = _
CrystalDecisions.Shared.ExportDestinationType.MicrosoftMail
'Instantiate an Email options object and set its properties
Dim Options As CrystalDecisions.Shared.MicrosoftMailDestinationOptions = _
New CrystalDecisions.Shared.MicrosoftMailDestinationOptions
Options.UserName = UserName
Options.Password = Password
Options.MailSubject = Subject
Options.MailMessage = Message
Options.MailToList = MailTo
Options.MailCCList = CCList
'Assign the options object to the report
MyReport.ExportOptions.DestinationOptions = Options
End Sub

This procedure first sets the report object’s destination type to be MicrosoftMail. Then it creates a new options variable and assigns the parameters to the appropriate properties. The last step assigns the options object to the DestinationOptions property of the report object.

Note: The attachment’s filename is created automatically and it is in the format of “Temp_” followed by a series of random numbers (similar to a GUID). You can’t specify the filename that the report gets exported to. Since email is a common method of sending viruses, this could cause the receiver to be initially alarmed or a spam filter might delete the email before it ever gets their Inbox. Make sure the recipient knows about this anomaly prior sending it to them.