I have a Java application running on Tomcat which needs to generate an email to Outlook on the connecting client's computer. Currently my code is always directing the email to Outlook on the server where tomcat is running and not to the connecting client. I have attached the code that I am using to connect to Outlook below. Any help to achieve this will be appreciated.
package org.outlook.emails;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
public class EmailAPI
{
private ActiveXComponent ol;
private Dispatch outlook;
private Object mapi[] = new Object[1];
private Object email[] = new Object[1];
public EmailAPI()
{
mapi[0] = "MAPI";
email[0] = 0;
ol = new ActiveXComponent("Outlook.Application");
outlook = ol.getObject();
Dispatch.call(outlook,"GetNamespace",mapi).toDispatch();
}
public void createEmail(String receiver,String cc,String subject, String body, String attachments[])
{
Dispatch mail = Dispatch.call(outlook,"CreateItem",email).toDispatch();
Dispatch inspector = Dispatch.get(mail, "GetInspector").getDispatch();
Dispatch recipients = Dispatch.call(mail, "Recipients").getDispatch();
Dispatch.call(recipients, "Add" , receiver);
Dispatch.put(mail, "CC",cc);
Dispatch.put(mail, "Subject", subject);
Dispatch.put(mail, "Body", body);
if(attachments.length>0)
{
Dispatch attachs = Dispatch.get(mail, "Attachments").toDispatch();
for(Object attachment : attachments)
{
Dispatch.call(attachs, "Add", attachment);
}
}
Dispatch.call(mail, "Send");
}
}
Thank you.
Med