Skip to Content
Technical Articles

Utility to Update Sender Email Address

Hi,

There is a requirement to update the Sender Email Address of all the recurring instances in my current engagement.  I am sharing the code here, which will be useful to others who has similar requirement.  I have created it as .java file.  Please ensure that cecore.jar, cesession.jar,celib.jar,corbaidl.jar, logging.jar & ebus405.jar are added to classpath.  These jar files will be available at <BOE Installationpath>\common\java\lib.

import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.*;
import com.businessobjects.sdk.plugin.desktop.publication.*;
import com.crystaldecisions.sdk.plugin.destination.smtp.*;

class MyApp {
public static void main (String[] args) {

IEnterpriseSession boIEnterpriseSession;
IInfoStore boInfoStore;
IInfoObjects boInfoObjects;
IInfoObjects boInfoObjects2;
IDestination Dest;
IDestination Dest_Succ;
IDestination Dest_Fail;

IInfoObject boRpt;
IPublication Pub;
IDestinationPlugin SmtpPlugin;

String user = “admin”;
String password = “password”;
String cmsName = “.”;
String cmsAuthType = “secEnterprise”;
int runs;
int prior_sid;
int qrysize;

prior_sid = 0;
try
{
boIEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(user, password, cmsName, cmsAuthType);
boInfoStore = (IInfoStore)boIEnterpriseSession.getService(“”, “InfoStore”);
System.out.println(“Successfully Connected”);
boInfoObjects = boInfoStore.query(“SELECT si_id FROM CI_INFOOBJECTS WHERE si_instance =1 and si_recurring = 1 “);
SmtpPlugin = (IDestinationPlugin) boInfoStore.query(“select * from ci_systemobjects where si_parentId=29 and si_name=’CrystalEnterprise.Smtp’ “).get(0);
if (boInfoObjects.getResultSize() % 50 != 0)
{
runs = boInfoObjects.getResultSize() / 50 +1;
}
else
{
runs = boInfoObjects.getResultSize() / 50;
}
System.out.println(“No. of iterations :” + runs);
for (int k = 1; k <= runs; k ++)
{
System.out.println(“Iteration :” + k + ” started.”);
boInfoObjects2 = boInfoStore.query(“SELECT top 50 * FROM CI_INFOOBJECTS WHERE si_instance =1 and si_recurring = 1  and si_id > ” + prior_sid + ” order by si_id”);
qrysize = boInfoObjects2.size();
for (int i= 0 ; i < qrysize ; i++)
{
boRpt = (IInfoObject) boInfoObjects2.get(i);
if (boRpt.getKind() == “Publication”)
{
Pub = (IPublication) boInfoObjects2.get(i);
for (int j = 0; j < Pub.getSchedulingInfo().getDestinations().size() ; j++)
{
Dest = (IDestination) Pub.getSchedulingInfo().getDestinations().get(j);
if (Dest.getName().trim().equalsIgnoreCase(“CrystalEnterprise.Smtp”))
{
if (! Dest.isSystemDefaultOptionsUsed())
{
Dest.copyToPlugin(SmtpPlugin);
ISMTPOptions SmtpOptions = (ISMTPOptions) SmtpPlugin.getScheduleOptions();

if ( SmtpOptions.getSenderAddress() != “”)

{
SmtpOptions.setSenderAddress(“Newemailid@domain.com“);

}
Dest.setFromPlugin(SmtpPlugin);
}
}
}
if(Pub.getSchedulingInfo().getNotifications().getDestinationsOnSuccess().size() !=0)
{
Dest_Succ = (IDestination) Pub.getSchedulingInfo().getNotifications().getDestinationsOnSuccess().get(0);
if  (! Dest_Succ.isSystemDefaultOptionsUsed())
{
Dest_Succ.copyToPlugin(SmtpPlugin);
ISMTPOptions SmtpOptions = (ISMTPOptions) SmtpPlugin.getScheduleOptions();
SmtpOptions.setSenderAddress(“Newemailid@domain.com“);
Dest_Succ.setFromPlugin(SmtpPlugin);
}
}
if(Pub.getSchedulingInfo().getNotifications().getDestinationsOnFailure().size() !=0)
{
Dest_Fail = (IDestination) Pub.getSchedulingInfo().getNotifications().getDestinationsOnFailure().get(0);
if  (! Dest_Fail.isSystemDefaultOptionsUsed())
{
Dest_Fail.copyToPlugin(SmtpPlugin);
ISMTPOptions SmtpOptions = (ISMTPOptions) SmtpPlugin.getScheduleOptions();
SmtpOptions.setSenderAddress(“Newemailid@domain.com“);
Dest_Fail.setFromPlugin(SmtpPlugin);
}
}
}
else
{
Dest =(IDestination) boRpt.getSchedulingInfo().getDestinations().get(0);
if (Dest.getName().trim().equalsIgnoreCase(“CrystalEnterprise.Smtp”))
{
if  (! Dest.isSystemDefaultOptionsUsed())
{
Dest.copyToPlugin(SmtpPlugin);
ISMTPOptions SmtpOptions = (ISMTPOptions) SmtpPlugin.getScheduleOptions();

if ( SmtpOptions.getSenderAddress() != “”)

{
SmtpOptions.setSenderAddress(“Newemailid@domain.com“);

}
Dest.setFromPlugin(SmtpPlugin);
}
}
if(boRpt.getSchedulingInfo().getNotifications().getDestinationsOnSuccess().size() !=0)
{
Dest_Succ = (IDestination) boRpt.getSchedulingInfo().getNotifications().getDestinationsOnSuccess().get(0);
if  (! Dest_Succ.isSystemDefaultOptionsUsed())
{
Dest_Succ.copyToPlugin(SmtpPlugin);
ISMTPOptions SmtpOptions = (ISMTPOptions) SmtpPlugin.getScheduleOptions();
SmtpOptions.setSenderAddress(“Newemailid@domain.com“);
Dest_Succ.setFromPlugin(SmtpPlugin);
}
}
if(boRpt.getSchedulingInfo().getNotifications().getDestinationsOnFailure().size() !=0)
{
Dest_Fail = (IDestination) boRpt.getSchedulingInfo().getNotifications().getDestinationsOnFailure().get(0);
if  (! Dest_Fail.isSystemDefaultOptionsUsed())
{
Dest_Fail.copyToPlugin(SmtpPlugin);
ISMTPOptions SmtpOptions = (ISMTPOptions) SmtpPlugin.getScheduleOptions();
SmtpOptions.setSenderAddress(“Newemailid@domain.com“);
Dest_Fail.setFromPlugin(SmtpPlugin);
}
}
}

prior_sid = boRpt.getID();
}
boInfoStore.commit(boInfoObjects2);
System.out.println(“Iteration :” + k + ” completed.”);
System.out.println(“last processed si_id – “+ prior_sid);
}
if( boIEnterpriseSession != null)
{
boIEnterpriseSession.logoff();
System.out.println(“Successfully disconnected”);
}
}
catch(SDKException sdkEx)
{
System.out.println(sdkEx.toString());
}

}
}

Be the first to leave a comment
You must be Logged on to comment or reply to a post.