public SmtpStatusCode?Send(User user, string verifyUrl)
        {
            var settings = _settingsManager.Current;

            if (String.IsNullOrWhiteSpace(settings.MailerAddress))
            {
                throw new Exception("There is no MailerAddress to send e-mail from. Perhaps you didn't set up the settings.");
            }
            var message = new EmailMessage
            {
                ToEmail   = user.Email,
                ToName    = user.Name,
                FromEmail = settings.MailerAddress,
                FromName  = settings.ForumTitle
            };

            message.Subject = String.Format(Resources.RegisterEmailSubject, settings.ForumTitle);
            string body;

            if (settings.IsNewUserApproved)
            {
                body = String.Format(NewUserApprovedEmail, settings.ForumTitle, settings.MailSignature, "\r\n");
            }
            else
            {
                body = String.Format(NewUserVerifyEmail, settings.ForumTitle, verifyUrl + "/" + user.AuthorizationKey, verifyUrl, user.AuthorizationKey, settings.MailSignature, "\r\n");
            }
            message.Body = body;
            return(_smtpWrapper.Send(message));
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
 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);
     }
 }
Exemple #4
0
		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);
			}
		}