+1 vote

I need to create a PHYSICAL .ics file and send it as an appointment, to make sure that the user can download it if his device doesn't support the ical (like the gmail in the android devices)?

by (450 points)

1 Answer

0 votes
Best answer

You'll need to use MimeFactory to create mime entity from the appointment object. Then simply use MailBuilder to create email message and add mime entity as a attachment:

Appointment appointment = new Appointment();

Event e = appointment.AddEvent();
e.Description = "Status meeting description";
e.Summary = "Status meeting summary";
e.Start = new DateTime(2015, 05, 10, 16, 00, 00);
e.End = new DateTime(2015, 05, 10, 17, 00, 00);

e.SetOrganizer(new Person("Alice", "alice@mail.com"));

e.AddParticipant(new Participant(
    "Bob", "bob@mail.com", ParticipationRole.Required, true));
e.AddParticipant(new Participant(
    "Tom", "tom@mail.com", ParticipationRole.Optional, true));
e.AddParticipant(new Participant(
    "Alice", "alice@mail.com", ParticipationRole.Required, true));

Alarm alarm = e.AddAlarm();

MailBuilder builder = new MailBuilder();
builder.Text = "text";
builder.From.Add(new MailBox("alice@mail.com", "Alice"));
builder.To.Add(new MailBox("bob@mail.com", "Bob"));

MimeCalendar att = new MimeFactory().CreateMimeCalendar(appointment);
IMail email = builder.Create();

using (Smtp smtp = new Smtp())
    smtp.Connect("smtp.server.com");  // or ConnectSSL for SSL
    smtp.UseBestLogin("user", "password");


by (298k points)