我希望开发一种各种电子邮件通知系统,用户可以在其中创建和编辑各种电子邮件模板,并将其分配给某些任务/功能。所有这些功能都只是某些评论的预定日期。所以说,审查定于2年后进行;用户希望能够在大约30天前(或其他任意时间)收到电子邮件通知,提醒他们进行实际审核。另一个问题是如何安排在特定日期发送的电子邮件,而不是它们在系统中,因此它是在日期而不是另一个事件上触发的。
已经设置了评论的安排,并且电子邮件模板的创建非常简单,但是如何设置电子邮件通知系统,可以在不在系统中时通过电子邮件发送给用户?如果有人能指出我正确的方向或可以给我一些建议,那将非常感激。谢谢大家。
答案 0 :(得分:0)
以下是入门链接:
https://msdn.microsoft.com/en-us/library/ms972339.aspx
https://msdn.microsoft.com/en-us/library/system.globalization.calendar(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient(v=vs.110).aspx
答案 1 :(得分:0)
您好,我已经完成创建控制台应用程序的操作,并且没有关闭控制台应用程序。
我写的最后一行是“ Console.ReadLine()”
当您收到新电子邮件时,将触发OnNotificationEvent事件。
下面是示例代码。
class Program
{
static void Main(string[] args)
{
EmailExchange emailExchange = new EmailExchange();
emailExchange.Domain = ConfigurationManager.AppSettings["Domain"];
emailExchange.EmailID = ConfigurationManager.AppSettings["EmailID"];
emailExchange.Password = ConfigurationManager.AppSettings["Password"];
emailExchange.Watch();
Console.ReadLine();
}
}
public class EmailExchange : IDisposable
{
public string Password { get; set; }
public string EmailID { get; set; }
public string Domain { get; set; }
public string ExchangeURL
{
get { return "https://outlook.office365.com/EWS/Exchange.asmx"; }
}
private StreamingSubscriptionConnection connection = null;
private ExchangeService service = null;
public void Watch()
{
service = new ExchangeService();
service.Credentials = new WebCredentials(EmailID, Password, Domain);
service.Url = new Uri(ExchangeURL);
StreamingSubscription streamingsubscription = service.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);
connection = new StreamingSubscriptionConnection(service, 5);
connection.AddSubscription(streamingsubscription);
connection.OnNotificationEvent += OnNotificationEvent;
connection.OnSubscriptionError += OnSubscriptionError;
connection.OnDisconnect += OnDisconnect;
connection.Open();
}
private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
Console.WriteLine("Disconnected");
if (!connection.IsOpen)
connection.Open();
}
private void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
{
}
private void OnNotificationEvent(object sender, NotificationEventArgs args)
{
foreach (var notification in args.Events)
{
if (notification.EventType != EventType.NewMail) continue;
var itemEvent = (ItemEvent)notification;
// add you code here
}
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}