Creating sendable Task in .msg file


#1

Hi,

I’m trying to create a Task trough Aspose.Email and then save it as a .msg file so it can be opened with Outlook to send to people.
I have succeeded in creating the task and saving it to .msg but the Recipients don’t seem to be used.
I saved a .msg from Outlook which behaves as I want it too: task.zip (10.2 KB)
Screenshot: image.png (13.8 KB)

This is a piece of the code I used:

MapiTask task = new MapiTask();
task.Subject = “My subject”;
task.Body = “Content”;
task.Mode = MapiTaskMode.NotAssigned;
task.Users.Owner = “Darius”;
task.Recipients.Clear();
task.Recipients.Add(“test@test.be”, “name”, MapiRecipientType.MAPI_TO);

// Initial test, but doest not retain Recipients after converting to MapiMessage
//task.Save(“MapiTask.msg”, TaskSaveFormat.Msg);

MemoryStream ms = new MemoryStream();
task.Save(ms, TaskSaveFormat.Msg);
ms.Position = 0;

var message = Aspose.Email.Mapi.MapiMessage.FromStream(ms);
// Recipients are empty, add them again
message.Recipients.Add(“test@test.be”, “name”, MapiRecipientType.MAPI_TO);
message.Save(“MapiTask.msg”, Aspose.Email.SaveOptions.DefaultMsgUnicode);


#2

@3PIT,

I have observed the message file, image and sample code shared by you. Can you please explain what else you are expecting to have in To field. You have used following statement and it added that to recipient.

task.Recipients.Add(“test@test.be”, “name”, MapiRecipientType.MAPI_TO);


#3

Hi @mudassir.fayyaz,

When I create the .msg file with the above code, I get a window like this in Outlook:
image.png (16.6 KB)

As you can see there is no Send button and the recipient is no where to be found.
Sample file: TempMapiTask.zip (2.0 KB)


#4

@3PIT,

I suggest you to please visit this documentation section for your kind reference. In case you still find issue, please feel free to share with us.


#5

@mudassir.fayyaz I read the information you linked to but it does not provide me with a solution.
If you try out the code I posted you will see that you will not get the sender field when opening the .msg file in Outlook.


#6

@3PIT,

I suggest you to please visit following link for your convenience. I hope the shared information will be helpful.


#7

@mudassir.fayyaz, thank you for the information.

We do not have access to an exchange server however…
As the .msg format clearly supports sending the task as an email, I supposed Aspose would be able to create such a file, but apparently it is not possible?


#8

@3PIT,

I suggest you to please try using following sample code on your end to serve the purpose.

        public static void TestTask1()
        {
            String path = @"C:\Email\MapiTask3.msg";
            var fileName = path;

            MapiTask task = new MapiTask();
            task.Subject = "My subject";
            task.Body = "Content";
            task.Mode = MapiTaskMode.NotAssigned;
            task.Users.Owner = "Darius";
            task.Recipients.Clear();
            task.Recipients.Add("test@test.be", "name", MapiRecipientType.MAPI_TO);
            task.Mode = MapiTaskMode.RequestEmbedded;

            MemoryStream ms = new MemoryStream();
            task.Save(ms, TaskSaveFormat.Msg);
            ms.Position = 0;

            var message = Aspose.Email.Mapi.MapiMessage.FromStream(ms)
;
            // Recipients are empty, add them again
            message.Recipients.Add("test@test.be", "name", MapiRecipientType.MAPI_TO);
            message.SetMessageFlags(MapiMessageFlags.MSGFLAG_READ);
            message.Save(fileName, Aspose.Email.SaveOptions.DefaultMsgUnicode);
        }

#9

@mudassir.fayyaz
Thank you for the response, I tried it out with the latest version of Aspose and indeed it works as expected.

We have an older version of Aspose however (4.9.0) so I tried porting the code to that version and came up with the following:

String path = @"C:\Email\MapiTask3.msg";
var fileName = path;

MapiTask task = new MapiTask();
task.Subject = "My subject";
task.Body = "Content";
task.Mode = MapiTaskMode.NotAssigned;
task.Users.Owner = "Darius";
task.Mode = MapiTaskMode.RequestEmbedded;

MemoryStream ms = new MemoryStream();
task.Save(ms, TaskSaveFormat.Msg);
ms.Position = 0;
        
var message = Aspose.Email.Outlook.MapiMessage.FromStream(ms);
message.Recipients.Add("test@test.be", "name", MapiRecipientType.MAPI_TO);
message.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_READ);
message.Save(fileName); 

This seems to be identical, but the Send button does not show when opening the saved file.
Do you know if there is anything I can do in our version to solve this issue?


#10

@3PIT,

I have observed your comments. Can you please try to use Aspose.Email latest version 19.5 on your end. I also like to inform that as per company policy support always provided based on new version so please try to use latest version and if there is still an issue than report here so that we may help you out.