src/EasyFrameWork/Notification/EmailNotificationProvider.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;
using Easy.Extend;
using Microsoft.Extensions.Logging;
using System.IO;
using Easy.Notification.Queue;
using System.Threading.Tasks;

namespace Easy.Notification
{
    public class EmailNotificationProvider : INotificationProvider, IEmailNotification
    {
        private readonly ISmtpProvider _smtpProvider;
        private readonly IEmailQueue _emailQueue;
        private readonly ILogger<EmailNotificationProvider> _logger;
        public EmailNotificationProvider(ISmtpProvider smtpProvider,
            ILogger<EmailNotificationProvider> logger,
            IEmailQueue emailQueue)
        {
            _smtpProvider = smtpProvider;
            _emailQueue = emailQueue;
            _logger = logger;
        }
        public virtual Type SupportType => typeof(EmailMessage);

        public virtual void Send(Message message)
        {
            var email = (EmailMessage)message;
            if (_emailQueue != null)
            {
                var smtpSetting = _smtpProvider.GetSmtpSetting();
                if (smtpSetting == null)
                {
                    _logger.LogError("SMTP Server is not ready, the email was dropped. For more information:{0}", "http://www.zkea.net/zkeacms/document/smtp-setting");
                    return;
                }
                _emailQueue.Send(new EmailContext(email, smtpSetting));
            }
            else
            {
                Send(email);
            }
        }
        public void Send(EmailMessage email)
        {
            MailMessage mailMessage = ConvertToMailMessage(email);
            SmtpClient client = GetSmtpClient();

            try
            {
                client.Send(mailMessage);
            }
            finally
后面还有 107 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。