Compartir a través de


Отправлем уведомление о встрече по e-mail (Outlook 2007 meeting appointment)

??????? ??????????? ? ??????? ?????????? ???????????? ?? ??????? ??????, ? meeting appointment ??? Outlook 2007.

????? MailMessage ????????? ????????? ? ?????? ????????? ?????????????. ? ??? ????? ? ????????? ? html ?????????????. ?? ??? ????, ????? ???????? ????? ????????????? ????? ????????????? ?????? ?????. ??? ??? ?? ????? ?????:

using

System;

using

System.Collections.Generic;

using

System.Linq;

using

System.Text;

using

System.Net.Mail;

using

System.Security.Principal;

using

System.DirectoryServices;

using

System.Net;

namespace

TestProj

{

public class Appointment

{

public Appointment(){}

public void EmailAppointment(DateTime StartDate, DateTime EndDate, String Location, String OrganizerName, String OrganizerEmail, String Summary, String Subject, MailAddressCollection AttendeeList)

{

MailMessage Mail =

new MailMessage();

//html

System.Net.Mime.ContentType HTMLType =

new System.Net.Mime.ContentType("text/html");

AlternateView HTMLView = AlternateView.CreateAlternateViewFromString(GetHTML(StartDate, EndDate, Location, OrganizerName, OrganizerEmail, Summary, Subject, AttendeeList), HTMLType);

// calendar

System.Net.Mime.ContentType CalendarType =

new System.Net.Mime.ContentType("text/calendar");

CalendarType.Parameters.Add(

"method", "REQUEST");

CalendarType.Parameters.Add(

"name", "meeting.ics");

AlternateView CalendarView = AlternateView.CreateAlternateViewFromString(GetCalendar(StartDate, EndDate, Location, OrganizerName, OrganizerEmail, Summary, Subject, AttendeeList), CalendarType);

CalendarView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;

Mail.AlternateViews.Add(HTMLView);

Mail.AlternateViews.Add(CalendarView);

Mail.From =

new MailAddress(OrganizerEmail);

foreach (MailAddress attendee in AttendeeList)

{

Mail.To.Add(attendee);

}

Mail.Subject = Subject;

SmtpClient Server =

new SmtpClient("server1", 25);

Server.Send(Mail);

}

private string GetHTML(DateTime StartDate, DateTime EndDate, String Location, String OrganizerName, String OrganizerEmail, String Summary, String Subject, MailAddressCollection AttendeeList)

{

string bodyHTML = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>\r\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">\r\n<META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 6.5.7652.24\">\r\n<TITLE>{0}</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<!-- Converted from text/plain format -->\r\n<P><FONT SIZE=2>Type:Single Meeting<BR>\r\nOrganizer:{1}<BR>\r\nStart Time:{2}<BR>\r\nEnd Time:{3}<BR>\r\nTime Zone:{4}<BR>\r\nLocation:{5}<BR>\r\n<BR>\r\n*~*~*~*~*~*~*~*~*~*<BR>\r\n<BR>\r\n{6}<BR>\r\n</FONT>\r\n</P>\r\n\r\n</BODY>\r\n</HTML>";

return string.Format(bodyHTML,

Summary,

OrganizerName,

StartDate.ToLongDateString() +

" " + StartDate.ToLongTimeString(),

EndDate.ToLongDateString() +

" " + EndDate.ToLongTimeString(),

System.

TimeZone.CurrentTimeZone.StandardName,

Location,

Summary);

}

private string GetCalendar(DateTime StartDate, DateTime EndDate, String Location, String OrganizerName, String OrganizerEmail, String Summary, String Subject, MailAddressCollection AttendeeList)

{

string DateFormatUsing="yyyyMMddTHHmmssZ";

string bodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US & Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";

bodyCalendar =

string.Format(bodyCalendar,

StartDate.ToUniversalTime().ToString(DateFormatUsing),

EndDate.ToUniversalTime().ToString(DateFormatUsing),

Location,

OrganizerName,

OrganizerEmail,

Guid.NewGuid().ToString("B"),

Summary,

Subject,

DateTime.Now.ToUniversalTime().ToString(DateFormatUsing),

AttendeeList.ToString());

return bodyCalendar;

}

}

}

Comments

  • Anonymous
    October 01, 2009
    Спасибо, воспользуемся! Как всегда вовремя )

  • Anonymous
    March 24, 2010
    день добрый! реализовала подобное решение, но вот в чем проблема: оригинатору уведомление приходит в почту, но не в календарь. и нет возможности его туда перекинуть. Таким образом, мы получаем неуправляемый, не удаляемый митинг и вдобавок не видим его в своем календаре. Есть ли какое то решение этой проблемы? Заранее спасибо.

  • Anonymous
    November 12, 2012
    Понимаю, что прошло уже больше 2-х лет. Но к вопросу присоеденяюсь. Устроителю события ни как не добавить это событие себе в календарь. :(