コード例 #1
0
        protected override void Context()
        {
            _smtpWrapper = new SmtpWrapper("localhost");
            _settingsProvider = new SettingsProvider();

            _emailService = new EmailService(_smtpWrapper, _settingsProvider);
        }
コード例 #2
0
        protected override void Context()
        {
            _sendEmailRequest = new SendMailRequest
                                    {
                                        To = "*****@*****.**",
                                        Subject = "important message for you bob",
                                        Message = "hi bob, this is not really that important. Just wanted to say hello."
                                    };

            _smtpClient = MockRepository.GenerateStub<ISmtpWrapper>();

            _smtpClient.Stub(x => x.Send(Arg<MailMessage>.Is.Anything))
                .WhenCalled(x => _mailMessagePassedToSmtpWrapper = x.Arguments[0] as MailMessage);

            _settingsProvider = MockRepository.GenerateStub<ISettingsProvider>();
            _settingsProvider.Stub(x => x.GetEmailSettings())
                .Return(new EmailSettings{AdminEmailAddress = AdminEmailAddress});

            _expectedMailMessage = new MailMessage();
            _expectedMailMessage.To.Add(_sendEmailRequest.To);
            _expectedMailMessage.From = new MailAddress(AdminEmailAddress);
            _expectedMailMessage.Subject = _sendEmailRequest.Subject;
            _expectedMailMessage.Body = _sendEmailRequest.Message;
            _expectedMailMessage.IsBodyHtml = true;

            _emailService = new EmailService(_smtpClient, _settingsProvider);
        }
コード例 #3
0
ファイル: MailWorker.cs プロジェクト: omidnasri/POPForums
        public async Task SendQueuedMessages(ISettingsManager settingsManager, ISmtpWrapper smtpWrapper, IQueuedEmailMessageRepository queuedEmailRepository, IEmailQueueRepository emailQueueRepository, IErrorLog errorLog)
        {
            if (!Monitor.TryEnter(SyncRoot))
            {
                return;
            }
            try
            {
                var messageGroup = new List <QueuedEmailMessage>();
                for (var i = 1; i <= settingsManager.Current.MailerQuantity; i++)
                {
                    var payload = await emailQueueRepository.Dequeue();

                    if (payload == null)
                    {
                        break;
                    }
                    if (payload.EmailQueuePayloadType != EmailQueuePayloadType.FullMessage)
                    {
                        throw new NotImplementedException($"EmailQueuePayloadType {payload.EmailQueuePayloadType} not implemented.");
                    }
                    var queuedMessage = await queuedEmailRepository.GetMessage(payload.MessageID);

                    if (queuedMessage == null)
                    {
                        break;
                    }
                    messageGroup.Add(queuedMessage);
                    await queuedEmailRepository.DeleteMessage(queuedMessage.MessageID);
                }
                Parallel.ForEach(messageGroup, message =>
                {
                    try
                    {
                        smtpWrapper.Send(message);
                    }
                    catch (Exception exc)
                    {
                        if (message == null)
                        {
                            errorLog.Log(exc, ErrorSeverity.Email, "There was no message for the MailWorker to send.");
                        }
                        else
                        {
                            errorLog.Log(exc, ErrorSeverity.Email, $"MessageID: {message.MessageID}, To: <{message.ToEmail}> {message.ToName}, Subject: {message.Subject}");
                        }
                    }
                });
            }
            catch (Exception exc)
            {
                errorLog.Log(exc, ErrorSeverity.Error);
            }
            finally
            {
                Monitor.Exit(SyncRoot);
            }
        }
コード例 #4
0
ファイル: MailWorker.cs プロジェクト: popotans/POPForums
 public void SendQueuedMessages(ISettingsManager settingsManager, ISmtpWrapper smtpWrapper, IQueuedEmailMessageRepository queuedEmailRepository, IErrorLog errorLog)
 {
     if (!Monitor.TryEnter(_syncRoot))
     {
         return;
     }
     try
     {
         var messageGroup = new List <QueuedEmailMessage>();
         for (var i = 1; i <= settingsManager.Current.MailerQuantity; i++)
         {
             var queuedMessage = queuedEmailRepository.GetOldestQueuedEmailMessage();
             if (queuedMessage == null)
             {
                 break;
             }
             messageGroup.Add(queuedMessage);
             queuedEmailRepository.DeleteMessage(queuedMessage.MessageID);
         }
         Parallel.ForEach(messageGroup, message =>
         {
             try
             {
                 smtpWrapper.Send(message);
             }
             catch (Exception exc)
             {
                 if (message == null)
                 {
                     errorLog.Log(exc, ErrorSeverity.Email, "There was no message for the MailWorker to send.");
                 }
                 else
                 {
                     errorLog.Log(exc, ErrorSeverity.Email, String.Format("MessageID: {0}, To: <{1}> {2}, Subject: {3}", message.MessageID, message.ToEmail, message.ToName, message.Subject));
                 }
             }
         });
     }
     catch (Exception exc)
     {
         errorLog.Log(exc, ErrorSeverity.Error);
     }
     finally
     {
         Monitor.Exit(_syncRoot);
     }
 }
コード例 #5
0
        public Repository()
        {
            SmtpWrapper = new DefaultSmtpWrapper();
            EmailWrapper = new DefaultEmailWrapper();
            InvoiceWrapper = new DefaultInvoiceWrapper();
            ClientsWrapper = new DefaultClientsWrappers();
            CompanyInformationWrapper = new DefaultCompanyInformationWrapper();
            TermsWrapper = new DefaultTermsWrapper();
            StorageWrapper = new DefaultStorageWrapper();

            EnsureConfigsExist();

            SmtpWrapper.Load();
            EmailWrapper.Load();
            InvoiceWrapper.Load();
            ClientsWrapper.Load();
            CompanyInformationWrapper.Load();
            TermsWrapper.Load();
            StorageWrapper.Load();
        }
コード例 #6
0
ファイル: MailWorker.cs プロジェクト: andyliyuze/POPForums
		public void SendQueuedMessages(ISettingsManager settingsManager, ISmtpWrapper smtpWrapper, IQueuedEmailMessageRepository queuedEmailRepository, IErrorLog errorLog)
		{
			if (!Monitor.TryEnter(_syncRoot))
			{
				return;
			}
			try
			{
				var messageGroup = new List<QueuedEmailMessage>();
				for (var i = 1; i <= settingsManager.Current.MailerQuantity; i++)
				{
					var queuedMessage = queuedEmailRepository.GetOldestQueuedEmailMessage();
					if (queuedMessage == null)
						break;
					messageGroup.Add(queuedMessage);
					queuedEmailRepository.DeleteMessage(queuedMessage.MessageID);
				}
				Parallel.ForEach(messageGroup, message =>
				{
					try
					{
						smtpWrapper.Send(message);
					}
					catch (Exception exc)
					{
						if (message == null)
							errorLog.Log(exc, ErrorSeverity.Email, "There was no message for the MailWorker to send.");
						else
							errorLog.Log(exc, ErrorSeverity.Email, String.Format("MessageID: {0}, To: <{1}> {2}, Subject: {3}", message.MessageID, message.ToEmail, message.ToName, message.Subject));
					}
				});
			}
			catch (Exception exc)
			{
				errorLog.Log(exc, ErrorSeverity.Error);
			}
			finally
			{
				Monitor.Exit(_syncRoot);
			}
		}
コード例 #7
0
		public NewAccountMailer(ISettingsManager settingsManager, ISmtpWrapper smtpWrapper)
		{
			_settingsManager = settingsManager;
			_smtpWrapper = smtpWrapper;
		}
コード例 #8
0
 public NewAccountMailer(ISettingsManager settingsManager, ISmtpWrapper smtpWrapper)
 {
     _settingsManager = settingsManager;
     _smtpWrapper     = smtpWrapper;
 }
コード例 #9
0
ファイル: EmailService.cs プロジェクト: AcklenAvenue/PRTools
 public EmailService(ISmtpWrapper smtpWrapper, ISettingsProvider settingsProvider)
 {
     _smtpWrapper = smtpWrapper;
     _settingsProvider = settingsProvider;
 }