Gửi yêu cầu họp
Contents
[
Hide
]
VSTO
Để sử dụng các lớp Outlook, Outlook.Interop phải được tham chiếu trong dự án .NET của bạn. Đoạn mã dưới đây:
- Tạo một yêu cầu họp.
- Thiết lập các thuộc tính như tiêu đề, nội dung, địa điểm và thời gian.
- Gửi yêu cầu họp tới người nhận.
- Microsoft Outlook phải được cài đặt trên hệ thống nơi ứng dụng mẫu này sẽ chạy.
// 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
Đoạn mã dưới đây sử dụng Aspose.Email cho .NET để gửi yêu cầu họp. Đầu tiên, tạo yêu cầu họp bằng lớp Aspose.Email.Appointment. Sau đó gửi email, đính kèm yêu cầu họp và gửi email bằng lớp Aspose.Email.Mail.SmtpClient.
Ưu điểm của việc sử dụng Aspose.Email cho .NET
Outlook Interop yêu cầu Microsoft Outlook phải được cài đặt trên hệ thống nơi nó được sử dụng. Aspose.Email cho .NET không yêu cầu Microsoft Outlook được cài đặt và phù hợp cho các ứng dụng máy chủ.
// 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);
##Tải Mã Mẫu