Setting scheduling options for SMTP

Now that you have the InfoObject for the SMTP destination, you can use the PluginInterface to set the scheduling options that are specific to SMTP. These include:

For example:

SMTPSchedulingOptions = SMTP.PluginInterface("").ScheduleOptions;

SMTPSchedulingOptions.DomainName = "rd.crystaldecisions.com";

SMTPSchedulingOptions.Subject = "Here is you world sales report";

SMTPSchedulingOptions.ToAddresses.Add ("Joel.Mudge@CrystalDecisions.com");

SMTPSchedulingOptions.CCAddresses.Add ("Tomi.Eng@CrystalDecisions.com");

SMTPSchedulingOptions.Port = 25;

SMTPSchedulingOptions.SenderAddress = "Robert@Nowhere.com";

SMTPSchedulingOptions.ServerName = "mail";

SMTPSchedulingOptions.Attachments.Add("application/rpt","World Sales Report.rpt");

SMTPSchedulingOptions.Message = "The up-to-date world sales report. Rob.";

SMTPSchedulingOptions.SMTPAuthentication=0; //No authentication.

SMTPSchedulingOptions.SMTPUserName = "";

SMTPSchedulingOptions.SMTPPassword = "";

Once the SMTP options are set, you must copy them into the Report.ScheduleInfo.Destination. This will cause the instance to be transferred via SMTP to the people specified in the CC and recipient addresses after it has been processed. For example:

Report.SchedulingInfo.Destination.SetFromPlugin (SMTP);

You are now ready to schedule the report using the InfoStore. The complete example for scheduling via SMTP is given below. You can now choose to go to:

Example

function ScheduleToSMTP(IStore,ReportId, DomainName, ServerName, Subject, SenderAddress, RecipientAddresses, Port, Attachment, CCAddresses, Body, Authentication, UserName, Password)

{

    var Reports = IStore.Query("SELECT SI_ID, SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID="+ReportId);

    if (Reports.Count == 0)

    {

        return;

    }

    var Report=Reports.Item(1);

    

    var ScheduleInfo ;

    //Create an interface to the scheduling options for the report.

    ScheduleInfo = Report.SchedulingInfo;

    // Run the report once.

    ScheduleInfo.Type = 0;

    // Run it right now.

    ScheduleInfo.RightNow = true;

    

    var SMTP;

    var SMTPSchedulingOptions;

    SMTP = IStore.Query("Select Top 1* From CI_SYSTEMOBJECTS Where SI_PARENTID=29 and SI_NAME='CrystalEnterprise.SMTP'").Item(1);

    SMTPSchedulingOptions = SMTP.PluginInterface("").ScheduleOptions;

    SMTPSchedulingOptions.DomainName = DomainName;

    SMTPSchedulingOptions.Subject = Subject;

    for(k=0;k<RecipientAddresses.length;k++)

        SMTPSchedulingOptions.ToAddresses.Add (RecipientAddresses[k]);

    for(k=0;k<CCAddresses.length;k++)

        SMTPSchedulingOptions.CCAddresses.Add (CCAddresses[k]);

    SMTPSchedulingOptions.Port = Port;

    SMTPSchedulingOptions.SenderAddress = SenderAddress;

    SMTPSchedulingOptions.ServerName = ServerName;

    SMTPSchedulingOptions.Attachments.Add(Report.Mimetype,Attachment);

    SMTPSchedulingOptions.Message = Body;

    SMTPSchedulingOptions.SMTPAuthentication=Authentication;

    SMTPSchedulingOptions.SMTPUserName = UserName;

    SMTPSchedulingOptions.SMTPPassword = Password;

    

    ScheduleInfo.Destination.SetFromPlugin (SMTP);

    

    //Tell the APS to schedule the report.

    IStore.Schedule (Reports);

}



Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com