Beispiel #1
0
        public override MailingResponse ExecuteState()
        {
            var response = new MailingResponse {
                Success  = false,
                StatusId = MailingConsts.BulkEmailStatusErrorId
            };
            var bulkEmailId = Context.BulkEmailEntity.PrimaryColumnValue;

            if (!ValidateBulkEmail(Context.BulkEmailEntity))
            {
                return(response);
            }
            var validationResult = ActiveContactsHelper.ValidatePermissionEditBulkEmail(UserConnection);

            if (validationResult.Code == ActiveContactsValidationResult.Error)
            {
                MailingUtilities.Log.ErrorFormat(
                    "[CESMaillingProvider.ExecuteSendMessage]: License check failed. SessionId: {0}.",
                    Context.SessionId);
                BulkEmailEventLogger.LogError(bulkEmailId, DateTime.UtcNow, GetLczStringValue("BatchSendEvent"),
                                              GetLczStringValue("LicenceErrorMsg"), UserConnection.CurrentUser.ContactId);
                return(new MailingResponse {
                    Success = false,
                    StatusId = MailingConsts.BulkEmailStatusErrorId,
                    RemindingLczStringCode = validationResult.Message
                });
            }
            if (!PingProvider())
            {
                MailingUtilities.Log.ErrorFormat(
                    "[CESMaillingProvider.ExecuteSendMessage]: CESApi.Ping Fails. SessionId: {0}.", Context.SessionId);
                BulkEmailEventLogger.LogError(bulkEmailId, DateTime.UtcNow, GetLczStringValue("BatchSendEvent"),
                                              GetLczStringValue("CloudUnreachableMsg"), UserConnection.CurrentUser.ContactId);
                return(new MailingResponse {
                    Success = false,
                    StatusId = MailingConsts.BulkEmailStatusErrorId,
                    RemindingLczStringCode = "CESPingFailsMsg"
                });
            }
            RegisterSenderDomain(Context.BulkEmailEntity.GetTypedColumnValue <string>("SenderEmail"));
            response.Success  = true;
            response.StatusId = MailingConsts.BulkEmailStatusWaitingBeforeSendId;
            return(response);
        }
        public override MailingResponse ExecuteState()
        {
            var startSendingTime = DateTime.UtcNow;
            var bulkEmail        = (BulkEmail)Context.BulkEmailEntity;

            MailingUtilities.Log.InfoFormat(
                "[CESMaillingProvider.ExecuteSendMessage]: Start: " + "BulkEmail.Id: {0}, SessionId: {1}", bulkEmail.Id,
                Context.SessionId);
            try {
                var validationResult = ActiveContactsHelper.ValidatePermissionEditBulkEmail(UserConnection);
                if (validationResult.Code == ActiveContactsValidationResult.Error)
                {
                    MailingUtilities.Log.ErrorFormat(
                        "[CESMaillingProvider.ExecuteSendMessage]: License check failed. SessionId: {0}.",
                        Context.SessionId);
                    BulkEmailEventLogger.LogError(bulkEmail.Id, DateTime.UtcNow, GetLczStringValue("BatchSendEvent"),
                                                  GetLczStringValue("LicenceErrorMsg"), UserConnection.CurrentUser.ContactId);
                    return(new MailingResponse {
                        Success = false,
                        StatusId = MailingConsts.BulkEmailStatusErrorId,
                        RemindingLczStringCode = validationResult.Message
                    });
                }
                if (!PingProvider(bulkEmail.Id))
                {
                    MailingUtilities.Log.ErrorFormat(
                        "[CESMaillingProvider.ExecuteSendMessage]: CESApi.Ping Fails. SessionId: {0}.",
                        Context.SessionId);
                    BulkEmailEventLogger.LogError(bulkEmail.Id, DateTime.UtcNow, GetLczStringValue("BatchSendEvent"),
                                                  GetLczStringValue("CloudUnreachableMsg"), UserConnection.CurrentUser.ContactId);
                    return(new MailingResponse {
                        Success = false,
                        StatusId = MailingConsts.BulkEmailStatusErrorId,
                        RemindingLczStringCode = "CESPingFailsMsg"
                    });
                }
                SetBulkEmailStatus(bulkEmail.Id, MailingConsts.BulkEmailStatusLaunchedId);
                InitBulkEmailCounters(bulkEmail.Id, false);
                BulkEmailEventLogger.LogInfo(bulkEmail.Id, startSendingTime, GetLczStringValue("StartSendingEmail"),
                                             GetLczStringValue("StartSendingEmailDescription"), UserConnection.CurrentUser.ContactId);
                var messageData = CreateSendMessageData(bulkEmail);
                ExecuteSendMessageTask(messageData);
                BulkEmailEventLogger.LogInfo(bulkEmail.Id, startSendingTime, GetLczStringValue("EmailSent"),
                                             GetLczStringValue("EmailSentDescription"), UserConnection.CurrentUser.ContactId);
            } catch (Exception e) {
                MailingUtilities.Log.ErrorFormat(
                    "[CESMaillingProvider.ExecuteSendMessage]: Error when execute send message for BulkEmail with Id: {0},",
                    e, bulkEmail.Id);
                BulkEmailEventLogger.LogError(bulkEmail.Id, DateTime.UtcNow, GetLczStringValue("BatchSendEvent"), e,
                                              GetLczStringValue("ExecuteSendMessageErrorMsg"), UserConnection.CurrentUser.ContactId);
                return(new MailingResponse {
                    Success = false,
                    StatusId = MailingConsts.BulkEmailStatusErrorId,
                    RemindingLczStringCode = "ExecuteSendMessageErrorMsg"
                });
            }
            return(new MailingResponse {
                Success = true,
                StatusId = MailingConsts.BulkEmailStatusFinishedId,
                RemindingLczStringCode = "CESMassMailingFinishedMsg"
            });
        }