I have a desktop application developed in Java, I am creating an email with HTML body then saving it as "email.msg", and immediately open that email file in Outlook application using JACOB.
Here is the code:
//initiate the emailprivatebooleansendEmailViaOutlook(Datadata){booleanemailSent;OutlookEmailjacobOutlook=newOutlookEmail();ActiveXComponentaxOutlook=newActiveXComponent("Outlook.Application");try{jacobOutlook.oOutlook=axOutlook.getObject();DispatchoNameSpace=axOutlook.getProperty("Session").toDispatch();StringemailBody=this.generateHTMLBody(data);StringemailSubject="subject line";StringrecipientTo=customTo;StringrecipientCC=customCc;String[]attachments=newString[]{"D:\\temp.txt"};jacobOutlook.createEmail(emailSubject,recipientTo,recipientCC,null,emailBody,attachments);}catch(Exceptione){thrownewRuntimeException(e);}finally{emailSent=true;}returnemailSent;}//create HTML email bodyprivateStringgenerateHTMLBody(AlarmDTOselectedAlarm,SiteDTOsiteDTO,AlarmStatusDtostatusDto,SeverityDtoseverityDto){System.out.println("Site Province: "+siteDTO);return"<HTML><BODY><table border='1' style='border:solid 1px gray;width: 20%;'>"+"<tr style='background-color: #0036A2; color:white;'>"+"<th style='width: 50%;'>Site Information</th>"+"<th style='width: 50%;'>Description</th>"+"</tr>"+"<tr>"+"<td style='background-color: #74BCF8;font-weight:semi-bold; color:black;'>TT No</td>"+"<td>"+data.getTtNo()+"</td>"+"</tr>"+"</table></BODY></HTML>";}//create actual email in .msg format, save it and open it in outlook voidcreateEmail(Stringsubject,StringrecipientTo,StringrecipientCC,StringrecipientBCC,Stringbody,String[]attachments){Dispatchmail=Dispatch.call(oOutlook,"CreateItem",email).toDispatch();Dispatch.put(mail,"Subject",subject);Dispatch.put(mail,"To",recipientTo);Dispatch.put(mail,"CC",recipientCC);Dispatch.put(mail,"BCC",recipientBCC);Dispatch.put(mail,"HTMLBody",body);Dispatch.call(mail,"SaveAs","D:\\JacobEmail.msg");Dispatch.call(mail,"Display");}
So far, it works fine.
The question is that I want to create email threads using the same approach, and append new email to the conversation based on the certain criterias.
How to achieve that?
Last edit: Sayed Hussainullah Sadat 2024-05-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a desktop application developed in Java, I am creating an email with HTML body then saving it as "email.msg", and immediately open that email file in Outlook application using JACOB.
Here is the code:
So far, it works fine.
The question is that I want to create email threads using the same approach, and append new email to the conversation based on the certain criterias.
How to achieve that?
Last edit: Sayed Hussainullah Sadat 2024-05-15