发送会议请求
Contents
[
Hide
]
VSTO
要使用 Outlook 类,必须在 .NET 项目中引用 Outlook.Interop。下面的代码片段:
- 创建会议请求。
- 设置主题、正文、地点和时间等属性。
- 将会议请求发送给收件人。
- 此示例应用程序运行的系统必须安装 Microsoft Outlook。
// Create an instance of Outlook Application class
Outlook.Application outlookApp = new Outlook.Application();
// Create an instance of AppointmentItem object and set the properties:
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);
oAppointment.Subject = "subject of appointment";
oAppointment.Body = "body text of appointment";
oAppointment.Location = "Appointment location";
// Set the start date and end dates
oAppointment.Start = Convert.ToDateTime("01/22/2010 10:00:00 AM");
oAppointment.End = Convert.ToDateTime("01/22/2010 2:00:00 PM");
// Save the appointment
oAppointment.Save();
// Send the appointment
Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
mailItem.To = "recipient@domain.com";
mailItem.Send();
Aspose.Email
下面的代码使用 Aspose.Email for .NET 发送会议请求。首先,使用 Aspose.Email.Appointment 类创建会议请求。然后使用 Aspose.Email.Mail.SmtpClient 类发送电子邮件并附加会议请求。
使用 Aspose.Email for .NET 的优势
Outlook Interop 需要在使用的系统上安装 Microsoft Outlook。而 Aspose.Email for .NET 不需要安装 Outlook,适用于服务器应用。
// Create attendees of the meeting
MailAddressCollection attendees = new MailAddressCollection();
attendees.Add("recipient1@domain.com");
attendees.Add("recipient2@domain.com");
// Set up appointment
Appointment app = new Appointment(
"Location", // location of meeting
DateTime.Now, // start date
DateTime.Now.AddHours(1), // end date
new MailAddress("organizer@domain.com"), // organizer
attendees); // attendees
// Set up message that needs to be sent
MailMessage msg = new MailMessage();
msg.From = "from@domain.com";
msg.To = "to@domain.com";
msg.Subject = "appointment request";
msg.Body = "you are invited";
// Add meeting request to the message
msg.AddAlternateView(app.RequestApointment());
// Set up the SMTP client to send email with meeting request
SmtpClient client = new SmtpClient("host", 25 ,"user", "password");
client.Send(msg);
##下载示例代码