在没有Outlook的情况下发送Outlook会议请求?

时间:2009-01-20 15:57:37

标签: c# .net outlook

我只是想知道是否可以在没有在服务器上安装Outlook并使用COM Interop(我想在服务器上不惜一切代价避免使用)的情况下向人们发送会议请求。

我们在Windows 2003域中安装了Exchange 2003,并且所有用户都是域用户。我想我可以发送'回合iCal / vCal或其他东西,但我想知道是否有一种适当的标准方式通过没有Outlook的Exchange发送会议请求?

如果重要的话,这是C#/ .net。

5 个答案:

答案 0 :(得分:49)

向Outlook发送会议请求(并将其识别出来)的方式如下:

  • 准备iCalendar文件,请务必设置这些附加属性,因为Outlook需要它们:
  • 准备multipart/alternative邮件:
    • 第1部分:text/html(或您喜欢的任何内容) - 此内容显示给“普通”邮件阅读器或作为后备内容,并以人类可读的形式包含事件摘要
    • 第2部分:text/calendar; method=REQUEST,保存ics文件的内容(标题method参数必须与ics中的方法匹配)。注意正确的文本编码,声明charset标头参数不会受到伤害。
    • 第3部分:(可选)附加.ics文件本身,以便普通邮件阅读器可以为用户提供点击的内容。 Outlook并不真正需要附件,因为它只读取text/calendar部分。
  • 将邮件发送给Outlook用户。如果一切正常,邮件会显示为会议请求,并在接受后在用户日历中自动输入出勤按钮和自动输入。
  • 设置处理响应的内容(它们会转到会议组织者)。我还无法让自动与会者跟踪与Exchange邮箱一起使用,因为该事件在组织者日历中不存在。 Outlook需要UID和SEQUENCES来满足它的期望,但是使用UID你就可以解决这个问题了。

有关ics文件格式的详细信息和特性的帮助,请务必访问iCalendar Specification Excerpts by Masahide Kanzaki。它们在黑暗中是一盏明灯,比在RFC 2445啃咬你的方式要好得多。但话说回来,也许.NET有一个方便的库。

答案 1 :(得分:8)

答案 2 :(得分:5)

iCalendar是一个很棒的通用解决方案,DDay.iCal库是从.NET完成此任务的好方法,但我相信Exchange Web Services(EWS)是原始环境中更好的解决方案问题(Exchange,C#/。NET)。

如果你使用的是.NET语言,比如C#,你应该使用EWS Managed API包装器,这大大简化了使用EWS的工作。

the docs开始,以下是如何使用EWS托管API创建会议并将请求发送给受邀者:

// Create the appointment.
Appointment appointment = new Appointment(service);

// Set properties on the appointment. Add two required attendees and one optional attendee.
appointment.Subject = "Status Meeting";
appointment.Body = "The purpose of this meeting is to discuss status.";
appointment.Start = new DateTime(2009, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("user1@contoso.com");
appointment.RequiredAttendees.Add("user2@contoso.com");
appointment.OptionalAttendees.Add("user3@contoso.com");

// Send the meeting request to all attendees and save a copy in the Sent Items folder.
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

答案 3 :(得分:4)

以下代码将以Outlook将呈现接受/拒绝按钮的方式发送会议请求。

请注意,每次会议UID必须是唯一的,我使用了GUID。

另请注意,您需要替换CREATED,DTSTART,DTEND,DTSTAMP,LAST-MODIFIED。这些是UTC日期/时间。

    var m = new MailMessage();

    m.Subject = "Meeting";

    m.Body = "";

    string iCal = 
@"BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:20140423T045933Z
DESCRIPTION:desc
DTEND:20140430T080000Z
DTSTAMP:20140423T045933Z
DTSTART:20140430T060000Z
LAST-MODIFIED:20140423T045933Z
LOCATION:location...
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=en-us:Summary...
TRANSP:OPAQUE
UID:D8BFD357-88A7-455C-86BC-C2CECA9AC5C6
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MS-OLK-AUTOFILLLOCATION:FALSE
X-MS-OLK-CONFTYPE:0
BEGIN:VALARM
TRIGGER:-PT60M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR";

    using (var iCalView = AlternateView.CreateAlternateViewFromString(iCal, new System.Net.Mime.ContentType("text/calendar")))
    {
        m.AlternateViews.Add(iCalView);

        var c = new SmtpClient();

        // Send message
        c.Send(m);
    }

这假设您在配置文件中配置了本地SMTP服务器:

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="no-reply@example.com">
        <network defaultCredentials="true" host="smtp.example.local" />
      </smtp>
    </mailSettings>
  </system.net>

答案 4 :(得分:3)

您可以使用iCal Standard (RFC 5545)

通过邮件向Outlook发送会议请求

您不能以这种方式发送待办事项。 您可以发送“约会”,但这些内容在Outlook中显示为.ics附件,必须“盲目”接受。

会议请求显示在Outlook中,预览效果很好,可以接受或拒绝。 发送程序可以在发送后修改或取消会议。

使用DDay.iCal .Net Library

创建有效的iCal项目很简单

以下代码是一个完整的工作示例。它使用有效的iCal会议请求构建一个字符串,并通过邮件发送。

代码使用以下内容创建邮件:

  • 简单邮件客户端的纯文本正文
  • 用于现代邮件客户端中的diplay的HTML正文
  • iCal会议请求为AlternateView(将在Outlook中显示)
  • iCal会议请求作为附件(可用于Outlook以外的邮件客户端)

代码显示了如何添加:

  • 描述文本为HTML,在outlook中看起来更好
  • 优先级,可见性(公共/私人/机密)
  • 可选的组织者(将在outlook中显示而不是邮件发件人)
  • 可选参加者
  • 可选警报
  • 会议的可选附件。将出现在outlook的日历中

一些重要细节:

  • 邮件发件人(或可选的组织者)和邮件收件人必须不同才能使其在Outlook中工作
  • Mime.ContentType中的.ics和METHOD中的方法必须匹配
  • 会议必须在未来使这项工作在展望
  • .ics部分必须是MIME邮件中的最后一个alternateView部分

有关outlook解释.ics文件的方式的详细信息详见[MS-OXCICAL]: iCalendar to Appointment Object Conversion Algorithm

我们将使用这些程序集:

using System;
using System.IO;
using System.Net.Mail;
using DDay.iCal;
using DDay.iCal.Serialization.iCalendar;

对于DDay.iCal足以下载DDay.iCal binary Files。如果你想添加一些功能,最好查看DDay.iCal源代码,因为文档已经过时,而且源代码包含非常完整的测试,可以识别它的所有功能。

const string filepath = @"C:\temp\ical.test.ics";
// use PUBLISH for appointments
// use REQUEST for meeting requests
const string METHOD = "REQUEST";

// Properties of the meeting request
// keep guid in sending program to modify or cancel the request later
Guid uid = Guid.Parse("2B127C67-73B3-43C5-A804-5666C2CA23C9");
string VisBetreff = "This is the subject of the meeting request";
string TerminVerantwortlicherEmail = "mr.asker@myorg.com";
string bodyPlainText = "This is the simple iCal plain text msg";
string bodyHtml = "This is the simple <b>iCal HTML message</b>";
string location = "Meeting room 101";
// 1: High
// 5: Normal
// 9: low
int priority = 1;
//=====================================
MailMessage message = new MailMessage();

message.From = new MailAddress("sender@myorg.com");
message.To.Add(new MailAddress(TerminVerantwortlicherEmail));
message.Subject = "[VIS-Termin] " + VisBetreff;

// Plain Text Version
message.Body = bodyPlainText;

// HTML Version
string htmlBody = bodyHtml;
AlternateView HTMLV = AlternateView.CreateAlternateViewFromString(htmlBody,
  new System.Net.Mime.ContentType("text/html"));

// iCal
IICalendar iCal = new iCalendar();
iCal.Method = METHOD;
iCal.ProductID = "My Metting Product";            

// Create an event and attach it to the iCalendar.
Event evt = iCal.Create<Event>();
evt.UID = uid.ToString();

evt.Class = "PUBLIC";
// Needed by Outlook
evt.Created = new iCalDateTime(DateTime.Now);

evt.DTStamp = new iCalDateTime(DateTime.Now);
evt.Transparency = TransparencyType.Transparent;

// Set the event start / end times
evt.Start = new iCalDateTime(2014, 10, 3, 8, 0, 0); 
evt.End = new iCalDateTime(2014, 10, 3, 8, 15, 0); 
evt.Location = location;

//var organizer = new Organizer("the.organizer@myCompany.com");
//evt.Organizer = organizer;

// Set the longer description of the event, plain text
evt.Description = bodyPlainText;

// Event description HTML text
// X-ALT-DESC;FMTTYPE=text/html
var prop = new CalendarProperty("X-ALT-DESC");
prop.AddParameter("FMTTYPE", "text/html");
prop.AddValue(bodyHtml);
evt.AddProperty(prop);

// Set the one-line summary of the event
evt.Summary = VisBetreff;
evt.Priority = priority;

//--- attendes are optional
IAttendee at = new Attendee("mailto:Peter.Black@MyOrg.com");
at.ParticipationStatus = "NEEDS-ACTION";
at.RSVP = true;
at.Role = "REQ-PARTICIPANT";
evt.Attendees.Add(at);

// Let’s also add an alarm on this event so we can be reminded of it later.
Alarm alarm = new Alarm();

// Display the alarm somewhere on the screen.
alarm.Action = AlarmAction.Display;

// This is the text that will be displayed for the alarm.
alarm.Summary = "Upcoming meeting: " + VisBetreff;

// The alarm is set to occur 30 minutes before the event
alarm.Trigger = new Trigger(TimeSpan.FromMinutes(-30));

//--- Attachments
string filename = "Test.docx";

// Add an attachment to this event
IAttachment attachment = new DDay.iCal.Attachment();
attachment.Data = ReadBinary(@"C:\temp\Test.docx");
attachment.Parameters.Add("X-FILENAME", filename);
evt.Attachments.Add(attachment);

iCalendarSerializer serializer = new iCalendarSerializer();
serializer.Serialize(iCal, filepath);

// the .ics File as a string
string iCalStr = serializer.SerializeToString(iCal);

// .ics as AlternateView (used by Outlook)
// text/calendar part: method=REQUEST
System.Net.Mime.ContentType calendarType = 
  new System.Net.Mime.ContentType("text/calendar");
calendarType.Parameters.Add("method", METHOD);
AlternateView ICSview =
  AlternateView.CreateAlternateViewFromString(iCalStr, calendarType);

// Compose
message.AlternateViews.Add(HTMLV);
message.AlternateViews.Add(ICSview); // must be the last part

// .ics as Attachment (used by mail clients other than Outlook)
Byte[] bytes = System.Text.Encoding.ASCII.GetBytes(iCalStr);
var ms = new System.IO.MemoryStream(bytes);
var a = new System.Net.Mail.Attachment(ms,
  "VIS-Termin.ics", "text/calendar");
message.Attachments.Add(a);     

// Send Mail
SmtpClient client = new SmtpClient();
client.Send(message);

这里是ReadBinary()函数:

private static byte[] ReadBinary(string fileName)
{
    byte[] binaryData = null;
    using (FileStream reader = new FileStream(fileName,
      FileMode.Open, FileAccess.Read))
    {
        binaryData = new byte[reader.Length];
        reader.Read(binaryData, 0, (int)reader.Length);
    }
    return binaryData;
}

最容易在配置文件中配置SmtpClient,如下所示:

<configuration>
  ...
  <system.net>  
    <mailSettings>
      <smtp>
        <network host="mysmtp.server.com" port="25" userName="mySmtpUserName" password="myPassword" />
      </smtp>
    </mailSettings>
  </system.net>
  ...
相关问题