cancel
Showing results for 
Search instead for 
Did you mean: 

Sending mail to MA owner and user collaborators

Former Member
0 Kudos

1)We are able to send email to role-owner(ownerEmailId), but unable to send to role-collaborator. Please help me how to include the collaborator to email receiver's list.


2) Can we make changes in middle of the body of an email, like based on a condition I need to change the body.

When we are getting expiration date, we need to print it in middle of the body in mail. similarly when the expiration date is null, need to print some default test "dummy text xxxxxxxxxx".

==============

home = IBeanHomeLocator.lookup(session, com.sap.eso.api.contracts.ContractIBeanHomeIfc.sHOME_NAME);

ma = home.findByUniqueDocName(maId);

docOwner = ma.getDocumentOwnerUserReference();
userBean =  IapiAccountLocator.lookup(session, docOwner);

reqEmailId=userBean.getEmail();

usrIbean = IBeanHomeLocator.lookup(session, ma.getDocumentOwnerUserReference()).find(ma.getDocumentOwnerUserReference());
oUserCompanyRef= usrIbean.getFieldMetadata("BUYER_COMP").get(usrIbean) ;
compIbean = IBeanHomeLocator.lookup(session, oUserCompanyRef).find(oUserCompanyRef);
ownerEmailId=usrIbean.getEmail();
sourceEmail=compIbean.getFieldMetadata("SOURCE_EMAIL").get(compIbean);


newMaObjRef = ma.getObjectReference();

url1=IapiSystemUtilities.getSystemProperty(session, "custom", "ljlkjljlfadfaa", "")  +"/fsbuyer/contracts/contracts_summary,"+ma.getObjectReference().getObjectId();

url2=":1004?rqaction=load&hook=contract_uirq&allow_redirect=true";
url=url1+url2;

link1="xyz@abc.com";

String eMailBody1 = "xxx(yyy) System.\n\n<br><br>" ;

String eMailBody3= "<ul><li>Master Agreement Name: "+ "<b>" + ma.getDisplayName() + "\n</b></li>";
eMailBody3= eMailBody3 + "<li>Third Party name: "+ ma.getExtensionField("Z_VEN_NAME_001").get().getDisplayName() +"\n</li>";

/* here we need condition for expiration date is null and notnull*/

if(ma.getExpirationDate().toString()!= null && ma.getExpirationDate().toString()== 0){

eMailBody3= eMailBody3 + "<li>Expiration Date: "+ ma.getExpirationDate().toString() +"\n</li></ul>";

}else{

eMailBody3= eMailBody3 + "<li>Expiration Date: "+ "dummy text xxxxxxxxxx" +"\n</li></ul>";

}


//eMailBody3= eMailBody3 + "<li>Expiration Date: "+ ma.getExpirationDate().toString() +"\n</li></ul>";

eMailBody3= eMailBody3 + "To review the document click the following link:<br>";

eMailBody3= eMailBody3 + "<a href="+url1+url2+">"+url1+url2+"</a><br><br>";

eMailBody3= eMailBody3 + " Do not reply to this message. If you have any questions or difficulty using this application, please contact support at <a href="+link1+"> adfadfa@cfadfa.com.</a>";


mSendMailToUser(sourceEmail, ownerEmailId, "Agreement: " + ma.getDisplayName() +collabRole+" " + "Renewal Reminder ",  eMailBody1+"\n\nMaster Agreement " + ma.getDocumentId() + " " + "is scheduled for a renewal review on  " + " " + " "+ ma.getRenewalReminder().toString()+"\n"+eMailBody3);

}

===========

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Siva,

By seeing the code snippet, I understood that your requirement is to send an email to the owner and role-collaborator regarding Agreement renewal reminder based on some condition.

We had a similar kind of requirment and we have followed below method to achieve the requirement.

If you have interest you can follow.  

We have gone through  the Vikram Shanmugasundaram's blog http://scn.sap.com/community/sourcing/blog/2012/08/08/query-iapis--a-good-alternative-for-dbhandle

First we have created a query, in that we get the MA Id,Name,expire/renewal dates,Owner and required collaborators with email ids.Then we have used query IAPIs in script to get the query result set data. By using the result data we have implemented email body and sending mails.

Please see below code snippet.

//sendmail function

public void sendEmail(String docID,String MAName1,String collabName,String email,String supplierName,String expirationDate,String Agtowner,String owneremail)

{

String mailSubject = new StringBuffer().append("Agreement: ").append(MAName1).append(" Renewal/Expiry reminder notification").toString();

String user="Test@TestSMTP.com";

// Create properties, get Session

Properties props = System.getProperties();

props.put("mail.transport.protocol", "smtp");

props.put("mail.smtp.host", host);

props.put("mail.debug", "false");

props.put("mail.smtp.auth", "false");

props.put("mail.user",user);

props.put("mail.from",email);

//Authenticator object need to be set to null

Session d_session = Session.getInstance(props,null);

Message msg = new MimeMessage(d_session);

msg.setFrom(new InternetAddress(user));

InternetAddress[] address = {new InternetAddress(email)};

msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject(mailSubject);

MimeMultipart mp = new MimeMultipart();

MimeBodyPart mbp1= new MimeBodyPart();

String htmlText =

"<b> Dear "+collabName+","+"</b>"+

"<br><br>"+

"You have a notification";     //you can write body of the mail as per your requirement.

mbp1.setContent(htmlText,"text/html");

mp.addBodyPart(mbp1);

msg.setContent(mp);

msg.setSentDate(new Date());

Transport.send(msg);

}

Try{ 

     HashMap filterPrompts = new HashMap(); 

    queryExec = IapiQueryExecFactory.createQueryExec(session,"Custom-Query-RenewalDate");//Passing query internal name.

    paramSet= queryExec.getParameterSet(session, "Custom-Query-RenewalDate");

    resultSet = queryExec.execute(filterPrompts);

    metaData = resultSet.getMetaData();

  while (resultSet.next())

{

MAId1 = resultSet.getString(0);

MAName =resultSet.getString(1);

SupplierName =resultSet.getString(3);

ExpirationDate = resultSet.getString(4);// You can write if else condition here

if(ExpirationDate = null)

{

   condition;

}

CollabName = resultSet.getString(5);

CollabEmail = resultSet.getString(6);

Owner =resultSet.getString(7);

ownerEmail         = resultSet.getString(8);

//Then call email function

sendEmail(MAId1,MAName,CollabName,CollabEmail,SupplierName,ExpirationDate,Owner,ownerEmail);

}

catch

{

}

Regards,

Lava