Create Calendar Appointment Independent of a Connection

I have an area of my web application that was originally coded to use the Outlook.Interop ActiveX to bring up a new appointment and fill out the data necessary. This code, as you can image, this is no longer supported in most browsers and it is time to change this behavior.

My first thought was to simply code to create a message and appointment, save the message as a .msg file, and then redirect the user to that file. But when I code this, Outlook cannot send the file, it simply says “You cannot send this item”. It almost seems like if you try to do this independent of a connection to Exchange, the message does not have the information needed to send.

Pasted below is the test code I have tried.

private static void BuildAppointment(string sender, string recipientList, string body)
{
[//Aspose.Email.Clients.Exchange.WebService.IEWSClient](https://aspose.email.clients.exchange.webservice.iewsclient/) client = GetExchangeEWSClient(“https://outlook.office365.com/ews/exchange.asmx”, "someone@somewhere.com", “asdfasdf”);


        MailAddressCollection recipients = new MailAddressCollection();
        char[] delims = new char[] { ';', ',', '|', ' ' };
        string[] addresses = recipientList.Split(delims, StringSplitOptions.RemoveEmptyEntries);
        foreach (string recipient in addresses)
            recipients.Add(new MailAddress(recipient));

        //recipients.Add(new MailAddress(sender));

        MailAddress organizer = new MailAddress(sender);

        MailMessage message = new MailMessage();
        message.To = recipients;
        message.From = sender;
        message.Subject = "Here is your appointment";
        message.Body = message.Subject;
        message.IsDraft = true;

        Appointment app = new Appointment("My Office", new DateTime(2019, 12, 12, 13, 30, 00), new DateTime(2019, 12, 12, 14, 00, 00), organizer, recipients)
        {
            MethodType = AppointmentMethodType.Request
        };

        message.AddAlternateView(app.RequestApointment());

        MapiMessage msg = MapiMessage.FromMailMessage(message);

        //client.CreateAppointment(app);
        msg.Save(body + ".msg");

        msg.Dispose();
        message.Dispose();
    }

Any guidance would be greatly appreciated.

@jheltibrand,

I have observed your requirements and have not been able to completely understand them and unable to figure out that what issue Aspose.Email is incurring on your end for meeting your requirement. Can you please share a working sample project along with test account with us that what you are trying to achieve using Aspose.Email and is getting failed.

I tried to strip down the example and attach it, but it is still too large, it won’t let me upload. Just take the method i pasted in and create an app, add your aspose.email reference, and you will have what you need.

The requirement is to build an appointment and present it to the user to send through their instance of Outlook. Notice there is no connection to a mail server in this code. The appointment needs to be added to the user’s calendar as organizer, and the attendees should all receive appointment requests.

I know this seems odd (and I feel like a crazy man as I explain this), normally you would connect to Exchange and save the appointment while logged onto Exchange as the organizer. It would show up on their calendar, and the attendees would get the appointment request. If the organizer canceled the meeting, the attendees would get notifications.

This is difficult because the customer (user of our application) is using either gmail or yahoo as their mail provider, so we have no option for connecting and interacting with it. I know there is an api for gmail that i may be able to leverage, but I am not going down that path.

@jheltibrand,

I have observed your requirements and suggest you to please visit this documentation link for possible options available in Aspose.Email for creating Calendar Items and saving them as MSG files. Later, MSG files can be pushed to email server when required.

What do you mean by “push to email server”? Remember, I have no connection to the mail server in question.

@jheltibrand,

It means that if you want to push MSG to email server. This is optional. Otherwise, in shared documentation link, you can find approach to save the Calendar as MSG or ICS file.

I am still not making myself clear.

I do not have access to their mail server. I want to simply build a file that they open with Outlook and can send. So far, everything I build, Outlook will not send it.

@jheltibrand,

I can understand your requirement. When you will create a MSG or ICS file, you can double click that and it can get opened in MS Outlook too. You may (If required) to send that further from MS Outlook.

I am doing just that. When I try to send, it simply says “Outlook cannot send this item”. What does it do for you?

@jheltibrand,

I request you to please follow the following steps. In the following images, I have dragged and drop a MSG file to my Outlook account. Then selected the message and forwarded it to desired destination.
Drag and Drop MSG.png (127.4 KB)

Send Email.png (91.2 KB)