How to display the on behalf of sender and date when sending task in java?

Dear,

We are using licensed apose 6.7.0(jdk 1.6) to achieve the requirement of sending task to specified user.

Right now the task could be successfully created and sent out, but on receiving it, the ‘on behalf of’ message could not display the sender and the sent date.

attachment is the task received.
Before asking for help here, i already searched many materials but no result.

From the task result.png, you could see the first rectangle just show the on behalf of but no sender address, and the second rectangle show the wrong date and time.

Codes:
String receiver = "example@example.com";

Calendar calendar = Calendar.getInstance();
Date startDate = calendar.getTime();
calendar.add(Calendar.DATE, 1);
Date endDate = calendar.getTime();
calendar.add(Calendar.DATE, -1);
Date reminderDate = calendar.getTime();

MapiTask task = new MapiTask(taskBean.getSubject(), “”, startDate, endDate);
task.setBodyContent(taskBean.getBody(), 1);
task.setReminderSet(true);
task.setReminderTime(reminderDate);

task.setPercentComplete(0);
task.setEstimatedEffort(0);
task.setActualEffort(0);
task.getUsers().setAssigner(MapiElectronicAddress.to_MapiElectronicAddress(alertSenderEmail));
task.setHistory(MapiTaskHistory.Assigned);


task.getUsers().setOwner(receiver);
task.getUsers().setLastAssigner(alertSenderEmail);
task.getUsers().setLastDelegate(alertSenderEmail);

task.getUsers().setDelegator(alertSenderEmail);

task.getUsers().setOwnership(MapiTaskOwnership.AssignersCopy);

task.setSensitivity(MapiSensitivity.Personal);
task.setStatus(MapiTaskStatus.NotStarted);
task.save(path + “MapiTask.msg”, TaskSaveFormat.Msg);


MailMessageLoadOptions loadOptions = new MailMessageLoadOptions();
loadOptions.setMessageFormat(MessageFormat.getMsg());
loadOptions.setFileCompatibilityMode(FileCompatibilityMode.PreserveTnefAttachments);

// load task from .msg file
MailMessage eml = MailMessage.load(path + “MapiTask.msg”, loadOptions);
eml.setFrom(new MailAddress(alertSenderEmail));
eml.setSubject(taskBean.getSubject());
eml.getTo().clear();
eml.setReadReceiptTo(MailAddressCollection.to_MailAddressCollection(receiver));
eml.setSensitivity(MailSensitivity.Personal);

// send email to:
MailAddress address = new MailAddress(receiver);
MailAddressCollection addresses = new MailAddressCollection();
addresses.addMailAddress(address);
eml.setTo(addresses);


// We should cover all scenarios for delivery notification
eml.setDeliveryNotificationOptions(DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay);
SmtpClient client = new SmtpClient(smtpServerAddress, Integer.parseInt(smtpServerPort), “”, “”);
client.setConnectionTimeout(SMTP_CONNECTION_TIMEOUT);
client.setTimeout(SMTP_OPERATION_TIMEOUT);

Log.info("Task is ready to sent to receiver: " + receiver);
client.send(eml);
Log.info("Task was sent to receiver via " + smtpServerAddress);

Hi,

Thank you for posting your inquiry.

We have tested your code sample and it works fine at our end. The email sent out has the “on behalf of” information included at top as you can see in the attached screenshot. We have made few changes in your code to meet the requirements of the latest version of the API as you can see in highlighted below. Please give it a try with the latest version of the API and let us know your feedback.

Sample Code:

String receiver = "example@example.com";

Calendar calendar = Calendar.getInstance();
Date startDate = calendar.getTime();
calendar.add(Calendar.DATE, 1);
Date endDate = calendar.getTime();
calendar.add(Calendar.DATE, -1);
Date reminderDate = calendar.getTime();

MapiTask task = new MapiTask(“Subject”, “”, startDate, endDate);
task.setBodyContent(“Body”, 1);
task.setReminderSet(true);
task.setReminderTime(reminderDate);

task.setPercentComplete(0);
task.setEstimatedEffort(0);
task.setActualEffort(0);
task.getUsers().setAssigner(MapiElectronicAddress.to_MapiElectronicAddress("to@d.com"));
task.setHistory(MapiTaskHistory.Assigned);


task.getUsers().setOwner(receiver);
task.getUsers().setLastAssigner("alertSenderEmail@domain.com");
task.getUsers().setLastDelegate("alertSenderEmail@domain.com");

task.getUsers().setDelegator("alertSenderEmail@domain.com");

task.getUsers().setOwnership(MapiTaskOwnership.AssignersCopy);

task.setSensitivity(MapiSensitivity.Personal);
task.setStatus(MapiTaskStatus.NotStarted);
task.save(“MapiTask.msg”, TaskSaveFormat.Msg);

MapiMessage msg = MapiMessage.fromFile(“MapiTask.msg”);

MailConversionOptions options = new MailConversionOptions();
options.setConvertAsTnef(true);

MailMessage eml = msg.toMailMessage(options);

MailAddressCollection coll = new MailAddressCollection();
coll.add("to@domain.com");
eml.setTo(coll);
SmtpClient client = new SmtpClient(“smtp.gmail.com”, 587, “username”, “password”);
client.setSecurityOptions(SecurityOptions.Auto);

client.send(eml);

Hi Kashif,

Thanks for your reply.But my problems are not solved.

From your screen shot, you could also find that the description ‘on behalf of on 1/1/1601 5:00AM’.

First problem: behind the on behalf of, there should be some address, such as on behalf of test@example.com;
Second problem: time and date 1/1/1601 5:00AM is not correct.

These two problems are my concern, i have no idea how to set them.

Hi,


Could you please create one such sample MSG file using MS Outlook and share with us where all this information is available? We need it to analyze the MSG file and investigate the issue further. Unfortunately, we are not able to generate such a sample MSG file that has this information for looking into it further. We appreciate your cooperation in this regard.

Hi Kashif,

see attachment test.zip for reference on created msg file with on behalf of.

Hi,


Please add the following lines of code to your application for setting these properties and let us know your feedback.

task.setLastUpdate(new Date());
task.getUsers().setLastUser("Delegator@domain.com");

Hi Kashif,

You solution worked, thank you very much.

Hi,


You are welcome and please feel free to write to us for any further inquiry related to Aspose.Email.