发送电子邮件WebAPI

时间:2018-08-02 16:41:10

标签: c# asp.net-mvc asp.net-mvc-4 asp.net-web-api

我有带有提醒类的webAPI项目

public class ReminderItem
{
    public Guid Id { get; set; }

    public string Subject { get; set; }

    public string Notes { get; set; }

    public DateTime RemindDate { get; set; }

    public Guid AuthorId { get; set; }

    public string AuthorEmail { get; set; }

    public bool IsActive { get; set; }

    public bool IsCancelled { get; set; }

}

我需要为其添加/更新/删除事件。这一切都已经完成并且可以进行。但是我还需要在日期时间将电子邮件发送到AuthorEmail。这是 RemindDate属性。但是我从来没有这样做。也许您可以帮助我,我该怎么做?或者我在哪里可以读到?因为我在程序启动时就知道如何做到这一点。就像现在用数据库中的日期时间检查日期时间一样。但是,当程序已经运行时,我如何才能做到这一点呢?

2 个答案:

答案 0 :(得分:1)

您可以在后台运行计划任务,并检查是否需要发送一些电子邮件。有关dotnetcore的说明,请参见此处: https://thinkrethink.net/2018/08/02/hostbuilder-ihost-ihostedserice-console-application/

答案 1 :(得分:0)

听起来像是您有一些延期的工作!我建议您使用sendgrid之类的电子邮件发送服务。他们有一个计划电子邮件API,您可以在其中发送详细信息,他们将等到日期和时间到后再发送(https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html

如果您想要使用SMTP的自己的解决方案,它将涉及更多,因为您将需要使用诸如azure服务总线队列之类的存储机制和一个Web作业来托管预定的工作。

相关问题