使用 Outlook Interop 和 Aspose.Email for Java 发送会议请求
Contents
[
Hide
]
我们的迁移技巧展示了如何使用 Aspose 产品来改进您的应用程序,并摆脱对传统自动化的依赖。
本迁移技巧向收件人发送会议请求。它演示了两种发送会议请求的方式:
我们还将讨论后者方法的优势。
使用 Outlook Interop 发送会议请求
要使用 Outlook 类,必须在 .NET 项目中引用 Outlook.Interop。下面的代码片段:
- 创建会议请求。
- 设置主题、正文、地点和时间等属性。
- 将会议请求发送给收件人。
此示例应用程序运行的系统必须安装 Microsoft Outlook。
编程示例
C#
// 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 for Java 发送会议请求
下面的代码使用 Aspose.Email for Java 发送会议请求。首先,使用该 Aspose.Email Appointment 类。然后发送电子邮件,附加会议请求,并使用该类发送电子邮件。 Aspose.Email SmtpClient 类。
使用 Aspose.Email for Java 的优势
Outlook Interop 需要在使用的系统上安装 Microsoft Outlook。Aspose.Email for Java 不需要安装 Microsoft Outlook,适用于服务器应用程序。
编程示例
// Create attendees of the meeting
MailAddressCollection attendees = new MailAddressCollection();
attendees.add("recipient1@domain.com");
attendees.add("recipient2@domain.com");
java.util.Calendar c = java.util.Calendar.getInstance();
Date startDate = c.getTime();
c.add(java.util.Calendar.HOUR_OF_DAY, 1);
Date endDate = c.getTime();
// Set up appointment
Appointment app = new Appointment(
"Location", // location of meeting
startDate, // start date
endDate, // end date
new MailAddress("organizer@domain.com"), // organizer
attendees); // attendees
// Set up message that needs to be sent
MailMessage msg = new MailMessage();
msg.setFrom(new MailAddress("from@domain.com"));
msg.setTo(MailAddressCollection.to_MailAddressCollection("to@domain.com"));
msg.setSubject("appointment request");
msg.setBody("you are invited");
// Add meeting request to the message
msg.addAlternateView(app.requestApointment());
// Set up the SMTP client to send email with meeting request
try (SmtpClient client = new SmtpClient("host", 25, "user", "password")) {
client.send(msg);
}