Reputation: 1
A c# process originaly in .net5 was sending email with Ecalendar structure for years but invitations are no more understood for users migrated under Exchange online.
The invitations are still working if sent to a gmail addresse for exemple. And the new servers can handle correctly an appointment sent from google calendar.
So I guess that mean that something in the c# process is not understood by Exchange online. The process is using the Class MailMessage but i tried other classes without success
here is an exemple simplified to the minimum using .net7. In exchange online we can access to the attachment (invitation.ics) but the message is not directly handled as a Icalendar invitation. In Gmail the message is well understood as an appointment.
using System;
using System.Net.Mail;
using System.Text;
try
{
SmtpClient clientSmtp = new SmtpClient("mysmtpserver");
using (MailMessage mail = new MailMessage("[email protected]", "[email protected]"))
{
mail.Subject = "test";
mail.Body = "test";
mail.To.Add("[email protected]");
// Ajouter le fichier iCalendar
byte[] fichierICalendar = CreerFichierICalendar();
mail.Attachments.Add(new System.Net.Mail.Attachment(new System.IO.MemoryStream(fichierICalendar), "invitation.ics", "text/calendar"));
clientSmtp.Send(mail);
Console.WriteLine("Invitation envoyée avec succès.");
}
}
catch (Exception ex)
{
Console.WriteLine("Une erreur s'est produite lors de l'envoi de la demande de réunion : " + ex.Message);
}
static byte[] CreerFichierICalendar()
{
// Création d'un événement iCalendar
StringBuilder builder = new StringBuilder();
builder.AppendLine("BEGIN:VCALENDAR");
builder.AppendLine("VERSION:2.0");
builder.AppendLine("PRODID:-//MyApp//EN");
builder.AppendLine("BEGIN:VEVENT");
builder.AppendLine("UID:" + Guid.NewGuid());
builder.AppendLine("DTSTAMP:" + DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ"));
builder.AppendLine("DTSTART:20230710T180000");
builder.AppendLine("DTEND:20230710T190000");
builder.AppendLine("SUMMARY:Événement spécial");
builder.AppendLine("DESCRIPTION:Événement spécial le 10 juin à 18h");
builder.AppendLine("END:VEVENT");
builder.AppendLine("END:VCALENDAR");
return Encoding.UTF8.GetBytes(builder.ToString());
}
Do i have to use another class ? or is there missing mandatory parameters ? Thanks
Upvotes: 0
Views: 24
Reputation: 1
it was a contentType issue that should include the parameters "method":"REQUEST" at the calendarView level
Upvotes: 0