SWT Java launch Outlook with attachment [message #1768547] |
Wed, 19 July 2017 20:54 |
Gary Shi Messages: 20 Registered: July 2013 |
Junior Member |
|
|
I have one Java SWT application and need to launch Outlook client to send email. I am attaching my Java code below and it is working fine basically. When Outlook client was launched and email data were populated into Outlook client. If no attachment, it is working fine. but if has attachment, Outlook client is not working. In detail, Outlook client was launched, but look like Outlook client was frozen, all buttons/links were frozen and not clickable, only top close button can be clicked. I am attaching image. You can see some controls on top of Outlook client page: "To...", "Cc...", "Subject" controls were on top of the page and they were duplicate. Send button is not clickable and this email can't be sent. I don't know what is wrong with me and any help/clue/suggestion will be appreciated it very much. Gary
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
.............
public static void launchOutlook(boolean hasAttach, Shell oneShell )
{
OleFrame frame = new OleFrame(oneShell, SWT.NONE);
// This should start outlook if it is not running yet
OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
// Now get the outlook application
OleClientSite site2 = new OleClientSite(frame, SWT.NONE, "Outlook.Application");
OleAutomation outlook = new OleAutomation(site2);
OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */).getAutomation();
setProperty(mail, "BodyFormat", 2 /* HTML */);
setProperty(mail, "Subject", "Mysubject");
setProperty(mail, "HtmlBody", "Mycontent");
setProperty(mail, "To", "oneEmail@gmail.com");
String[] attachmentPaths=null;
if(hasAttach){
attachmentPaths=new String[1];
attachmentPaths[0]="c:/temp/testFile.doc";
}
if (null != attachmentPaths)
{
for (String attachmentPath : attachmentPaths)
{
File file = new File(attachmentPath);
if (file.exists())
{
OleAutomation attachments = getProperty(mail, "Attachments");
invoke(attachments, "Add", attachmentPath);
}
}
}
invoke(mail, "Display" /* or "Send" */);
}
|
|
|
Powered by
FUDForum. Page generated in 0.01999 seconds