Book teams appointment with email notification

 using System;

using System.Net;

using System.Net.Mail;

using System.Text;


class Program

{

    static void Main()

    {

        string teamsLink = "https://teams.microsoft.com/l/meetup-join/xxxxxxxx";

        DateTime startUtc = new DateTime(2026, 1, 10, 10, 0, 0, DateTimeKind.Utc);

        DateTime endUtc = startUtc.AddMinutes(30);


        string ics = $@"

BEGIN:VCALENDAR

PRODID:-//YourApp//EN

VERSION:2.0

METHOD:REQUEST

BEGIN:VEVENT

UID:{Guid.NewGuid()}

DTSTAMP:{DateTime.UtcNow:yyyyMMddTHHmmssZ}

DTSTART:{startUtc:yyyyMMddTHHmmssZ}

DTEND:{endUtc:yyyyMMddTHHmmssZ}

SUMMARY:Project Discussion

DESCRIPTION:Join the Teams meeting:\n\n{teamsLink}

LOCATION:Microsoft Teams Meeting

ORGANIZER;CN=Organizer:mailto:organizer@example.com

ATTENDEE;ROLE=REQ-PARTICIPANT:mailto:user@example.com

STATUS:CONFIRMED

URL:{teamsLink}

END:VEVENT

END:VCALENDAR";


        var mail = new MailMessage();

        mail.From = new MailAddress("organizer@example.com");

        mail.To.Add("user@example.com");

        mail.Subject = "Teams Meeting Invitation";


        // Plain body

        mail.Body = $"Join the meeting:\n{teamsLink}";


        // Calendar MIME

        var calendarBytes = Encoding.UTF8.GetBytes(ics);

        var calendarAttachment =

            new Attachment(new System.IO.MemoryStream(calendarBytes),

            "invite.ics",

            "text/calendar; method=REQUEST; charset=UTF-8");


        mail.Attachments.Add(calendarAttachment);


        var smtp = new SmtpClient("smtp.example.com", 587)

        {

            EnableSsl = true,

            Credentials = new NetworkCredential("smtp_user", "smtp_password")

        };


        smtp.Send(mail);

    }

}


Comments

Popular posts from this blog

Key points while writting prompt for AI

How Create API in python using flask library