在C#中,使用Exchange Web Services (EWS) 庫可以實現設置郵件提醒功能。以下是一個簡單的示例:
首先,確保已安裝Microsoft.Exchange.WebServices庫。你可以通過NuGet包管理器來安裝:
Install-Package Microsoft.Exchange.WebServices -Version 2.2.166.0
然后,你可以使用以下代碼來設置郵件提醒:
using System;
using Microsoft.Exchange.WebServices.Data;
namespace ExchangeReminder
{
class Program
{
static void Main(string[] args)
{
// 設置Exchange服務器的URL和憑據
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Url = new Uri("https://your-exchange-server/ews/exchange.asmx");
service.Credentials = new WebCredentials("username", "password", "domain");
// 創建一封新郵件
EmailMessage message = new EmailMessage(service);
message.Subject = "Test reminder";
message.Body = "This is a test email with a reminder.";
message.ToRecipients.Add("recipient@example.com");
// 設置提醒
Reminder reminder = new Reminder();
reminder.Subject = "Reminder: Test reminder";
reminder.StartTime = DateTime.Now.AddMinutes(5);
reminder.EndTime = DateTime.Now.AddMinutes(10);
reminder.Location = "Conference Room A";
reminder.IsRecurring = false;
reminder.ItemId = message.Id;
// 將提醒添加到郵件中
message.Reminders.Add(reminder);
// 保存并發送郵件
message.Save();
message.SendAndSaveCopy();
}
}
}
請注意,這個示例僅用于演示目的。在實際應用中,你需要根據自己的需求進行相應的調整。