【问题标题】:Implement EmailService to notify User when Admin answer on post实施 EmailService 以在管理员回复帖子时通知用户
【发布时间】:2021-04-02 07:11:28
【问题描述】:

我正在寻找一些EmailService,它会在管理员回复his/her 帖子时通知用户。 我有在ASP.NET CORE MVC 中完成的 HelDesk Web 应用程序,到目前为止我有讨论,管理员可以回答用户票。每当管理员在工单中回答时,用户都应该在电子邮件中收到通知。

[HttpPost]
        public IActionResult SendDiscussion(int ticketId, string message)
        {
            var userName = User.FindFirstValue(ClaimTypes.Email);
            var account = _db.ApplicationUsers.SingleOrDefault(a => a.UserName.Equals(userName));

            var discussion = new Discussion
            {
                DateAndTime = DateTime.Now,
                Content = message,
                TicketId = ticketId,
                UserId = account.Id,
                ApplicationUser = account
            };
            _unitOfwork.Discussion.Add(discussion);
            _unitOfwork.Save();
            return RedirectToAction("Details", new { id = ticketId });
        }

电子邮件应仅发送给发布票证的用户。目前我有大约 10 个用户,但这个数字将增加到 100 个用户。 我检查了这篇文章,但我不确定这是MailKit 好的解决方案

Reference

谁能指导我并告诉我MailKit是为此目的的好解决方案吗?

【问题讨论】:

    标签: c# entity-framework-core asp.net-core-mvc


    【解决方案1】:

    我会推荐 FluentEmail 库,它很容易集成并为您提供所需的一切。

    这里是开源项目:https://github.com/lukencode/FluentEmail

    当您将这个包安装到您的项目时,它很容易使用:

    public IActionResult SendDiscussion(int ticketId, string message)
    {
        // Your code
    
        // Email variable should be passed as dependency injection or directly created here
        await email
            .To("test@test.test")
            .Subject("test email subject")
            .Body("This is the email body")
            .SendAsync();
    }
    

    【讨论】:

    • 感谢@Emin 的建议和帮助。我会试试这个解决方案
    • 还有一个问题。 To("test@test.test")我应该只传递用户登录的电子邮件。怎么做?我有 ApplicationUser 类,电子邮件应该只发送给提交帖子的用户。
    • 这是业务逻辑方面,您必须处理该部分以检索已登录的用户,并且只需向这部分代码提供电子邮件。您在这里有一些说明:lukelowrey.com/send-email-in-dotnet-core-with-fluent-email
    猜你喜欢
    • 2014-11-05
    • 2017-01-10
    • 2021-09-03
    • 2021-08-05
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    相关资源
    最近更新 更多