Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Send an EMAIL from external SOA appication

How to send an email from external SOA application?

I have tried below SOA api but proper explanation is not available in the documentation

 

EnvelopeService envelopeService = EnvelopeService.getService(Session.getConnection()); envelopeService.sendAndDeleteEnvelopes(new Envelope[] {envelope});

 

In the above API, how to fill Envelope object?

2 REPLIES
Solution
Solution
Accepted by topic author RavikumarML
‎07-19-2016 06:07 PM

Re: Send an EMAIL from external SOA appication

copied this from GTAC.

Should work together with the Hello Teamcenter SOA example.

 

try 
	{
		EnvelopeSend envelope = new EnvelopeSend(AppXSession.getConnection());
			 
		if(envelope.createEnvelope())
			envelope.sendEnvelope();
	}
catch (ServiceException e) 
	{
		e.printStackTrace();
	}



package com.teamcenter.hello;

import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException;
import com.teamcenter.services.strong.core.DataManagementService;
import com.teamcenter.services.strong.core.EnvelopeService;
import com.teamcenter.services.strong.core.SessionService;
import com.teamcenter.soa.client.Connection;
import com.teamcenter.soa.client.model.ModelObject;
import com.teamcenter.soa.client.model.ServiceData;
import com.teamcenter.soa.client.model.strong.Envelope;
import com.teamcenter.soa.client.model.strong.User;
import com.teamcenter.soa.exceptions.NotLoadedException;

public class EnvelopeSend 
{
	private EnvelopeService envService;
	private DataManagementService dmService;
	private SessionService session;
	
	private User user;
	private Envelope envelope;
	
	public EnvelopeSend(Connection connection) throws ServiceException
	{
		dmService = DataManagementService.getService(connection);
		envService = EnvelopeService.getService(connection);
		session = SessionService.getService(connection);
	
		user = session.getTCSessionInfo().user;
	}
	
	public boolean createEnvelope()
	{
		try
		{
			DataManagementService.CreateIn input = new DataManagementService.CreateIn();

			input.clientId = "ID:" + input.hashCode();
			input.data = new DataManagementService.CreateInput();
			input.data.boName = "Envelope"; 
			input.data.stringProps.put("object_name", "MyEnvelope Message"); // Subject
			input.data.stringProps.put("object_desc", "Message body...");
			input.data.tagArrayProps.put("listOfReceivers", newModelObject[]{ user }); 
			// To: receivers (User objects)
			input.data.tagArrayProps.put("contents", new ModelObject[]{ user.get_home_folder()}); // attachments (Folder objects)
						
			DataManagementService.CreateResponse resp = dmService.createObjects(new DataManagementService.CreateIn[]{ input });

			if(!ServiceDataError(resp.serviceData))
			{
				for(DataManagementService.CreateOut out : resp.output)
				{
					for(ModelObject obj : out.objects)
					{
						if(obj instanceof Envelope)
						{
							envelope =(Envelope)obj;
							return true;
						}
					}
				}
			}
		}
		catch(ServiceException e)
		{
			e.printStackTrace();
		}
		catch (NotLoadedException e) 
		{
			e.printStackTrace();
		}
		
		return false;
	}
	
	public void sendEnvelope()
	{
		ServiceData sdata = envService.sendAndDeleteEnvelopes(new Envelope[]{ envelope });
		
		ServiceDataError(sdata);		
	}
	
	protected boolean ServiceDataError(final ServiceData data)
	{
		if(data.sizeOfPartialErrors() > 0)
		{
			for(int i = 0; i < data.sizeOfPartialErrors(); i++)
			{
				for(String msg : data.getPartialError(i).getMessages())
					System.out.println(msg);
			}

			return true;
		}

		return false;
	}
}

HTH,

Xtof

Re: Send an EMAIL from external SOA appication

[ Edited ]

Hello,

 

Thank you for the replay. I received same solution from GTAC