示例#1
0
        public static void AddemailtoQueueNow(int contactID, string _emailAddress, string _name, string _body, string Hash)
        {
            if (Hash != "NoTImeFORLove")
                return;
            try
            {

                TG.ExpressCMS.DataLayer.Entities.Email _email = new DataLayer.Entities.Email();
                _email.IsDeleted = false;
                _email.Name = _name;
                _email.Details = _body;
                _email.Date = DateTime.Now.ToString("dd/MM/yyyy");
                _email.Type = DataLayer.Enums.RootEnums.EmailType.System;
                EmailManager.Add(_email);

                EmailQueue emailQueue = new EmailQueue();
                emailQueue.ContactID = contactID;
                emailQueue.DeliveryStatus = DataLayer.Enums.RootEnums.DeliveryStatus.Unknown;
                emailQueue.MailID = _email.ID;
                emailQueue.RecieverName = _name;
                emailQueue.ReciverAddress = _emailAddress;
                emailQueue.ScheduleDate = DateTime.Now.ToString("dd/MM/yyyy");
                emailQueue.ScheduleTime = DateTime.Now.ToShortTimeString();
                emailQueue.SenderAddress = EmailContext.LoadSmtpSettingsFileService().SernderAddress;
                emailQueue.SenderName = EmailContext.LoadSmtpSettingsFileService().SenderName;
                emailQueue.SendingStatus = DataLayer.Enums.RootEnums.SendingStatus.Pending;
                emailQueue.SentDate = DateTime.Now.ToString("dd/MM/yyyy");
                EmailQueueManager.Add(emailQueue);
                return;
            }
            catch (Exception ex)
            {
                UtilitiesManager.WriteFile(ExpressoConfig.GeneralConfigElement.GetPhysicalLoggingPath, ex.ToString(), false, true);
            }
            return;
        }
示例#2
0
        public void PopulateEmailQueue(SqlDataReader _dtr, EmailQueue obj)
        {
            int columnIndex = 0;
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_ID);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.ID = _dtr.GetInt32((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_RECIVERADDRESS);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.ReciverAddress = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_RECIEVERNAME);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.RecieverName = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SENDERADDRESS);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.SenderAddress = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SENDERNAME);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.SenderName = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_CONTACTID);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.ContactID = _dtr.GetInt32((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SCHEDULEDATE);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.ScheduleDate = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SCHEDULETIME);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.ScheduleTime = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SENDINGSTATUS);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.SendingStatus = (TG.ExpressCMS.DataLayer.Enums.RootEnums.SendingStatus)_dtr.GetInt32((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SENTDATE);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.SentDate = _dtr.GetString((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_DELIVERYSTATUS);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.DeliveryStatus = (TG.ExpressCMS.DataLayer.Enums.RootEnums.DeliveryStatus)_dtr.GetInt32((columnIndex));
            }
            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_MAILID);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.MailID = _dtr.GetInt32((columnIndex));
            }

            columnIndex = _dtr.GetOrdinal(EmailQueueDataMapper.CN_SENT_BY);
            if (!_dtr.IsDBNull(columnIndex))
            {
                obj.SentBy = _dtr.GetInt32((columnIndex));
            }
        }
示例#3
0
        public int Add(EmailQueue obj)
        {
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = INSERTEmailQueue;

            #region [Parameters]
            SqlParameter parameterID = new SqlParameter(PN_ID, SqlDbType.Int);
            parameterID.Value = obj.ID;
            parameterID.Direction = ParameterDirection.Output;
            _command.Parameters.Add(parameterID);
            SqlParameter parameterReciverAddress = new SqlParameter(PN_RECIVERADDRESS, SqlDbType.NVarChar);
            parameterReciverAddress.Value = obj.ReciverAddress;
            parameterReciverAddress.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterReciverAddress);
            SqlParameter parameterRecieverName = new SqlParameter(PN_RECIEVERNAME, SqlDbType.NVarChar);
            parameterRecieverName.Value = obj.RecieverName;
            parameterRecieverName.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterRecieverName);
            SqlParameter parameterSenderAddress = new SqlParameter(PN_SENDERADDRESS, SqlDbType.NVarChar);
            parameterSenderAddress.Value = obj.SenderAddress;
            parameterSenderAddress.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterSenderAddress);
            SqlParameter parameterSenderName = new SqlParameter(PN_SENDERNAME, SqlDbType.NVarChar);
            parameterSenderName.Value = obj.SenderName;
            parameterSenderName.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterSenderName);
            SqlParameter parameterContactID = new SqlParameter(PN_CONTACTID, SqlDbType.Int);
            parameterContactID.Value = obj.ContactID;
            parameterContactID.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterContactID);
            SqlParameter parameterScheduleDate = new SqlParameter(PN_SCHEDULEDATE, SqlDbType.NVarChar);
            parameterScheduleDate.Value = obj.ScheduleDate;
            parameterScheduleDate.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterScheduleDate);
            SqlParameter parameterScheduleTime = new SqlParameter(PN_SCHEDULETIME, SqlDbType.NVarChar);
            parameterScheduleTime.Value = obj.ScheduleTime;
            parameterScheduleTime.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterScheduleTime);
            SqlParameter parameterSendingStatus = new SqlParameter(PN_SENDINGSTATUS, SqlDbType.Int);
            parameterSendingStatus.Value = obj.SendingStatus;
            parameterSendingStatus.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterSendingStatus);
            SqlParameter parameterSentDate = new SqlParameter(PN_SENTDATE, SqlDbType.NVarChar);
            parameterSentDate.Value = obj.SentDate;
            parameterSentDate.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterSentDate);
            SqlParameter parameterDeliveryStatus = new SqlParameter(PN_DELIVERYSTATUS, SqlDbType.Int);
            parameterDeliveryStatus.Value = obj.DeliveryStatus;
            parameterDeliveryStatus.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterDeliveryStatus);
            SqlParameter parameterMailID = new SqlParameter(PN_MAILID, SqlDbType.Int);
            parameterMailID.Value = obj.MailID;
            parameterMailID.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterMailID);

            SqlParameter parameterSentBy = new SqlParameter(PN_SENT_BY, SqlDbType.Int);
            parameterSentBy.Value = obj.SentBy;
            parameterSentBy.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterSentBy);
            #endregion;

            _connection.Open();
            _command.ExecuteNonQuery();
            _connection.Close();
            obj.ID = Convert.ToInt32(parameterID.Value);
            return obj.ID;
        }
示例#4
0
        public static void SendEmail(int mailid, string colIntegers, string scheduledate, string scheduletime, string Hash)
        {
            if (Hash != "NoTImeFORLove")
                return;
            EmailSetting emailSetting = EmailContext.LoadSmtpSettingsFile();

            #region Adding Mail Queue
            string[] ids = colIntegers.Split(',');


            for (int i = 0; i < ids.Count(); i++)
            {
                if (ids[i] == "")
                    continue;

                int groupid = Convert.ToInt32(ids[i].ToString());
                IList<Contact> colContacts = ContactManager.GetByGroupID(groupid);
                for (int k = 0; k < colContacts.Count; k++)
                {
                    EmailQueue emailQueue = new EmailQueue();
                    emailQueue.ContactID = colContacts[k].ID;
                    emailQueue.DeliveryStatus = DataLayer.Enums.RootEnums.DeliveryStatus.Unknown;
                    emailQueue.MailID = mailid;
                    emailQueue.RecieverName = colContacts[k].FullName;
                    emailQueue.ReciverAddress = colContacts[k].Email;
                    emailQueue.ScheduleDate = scheduledate;
                    emailQueue.ScheduleTime = scheduletime;
                    emailQueue.SenderAddress = emailSetting.SernderAddress;
                    emailQueue.SenderName = emailSetting.SenderName;
                    emailQueue.SendingStatus = DataLayer.Enums.RootEnums.SendingStatus.Pending;
                    emailQueue.SentDate = DateTime.Now.ToString("dd/MM/yyyy");
                    EmailQueueManager.Add(emailQueue);
                }
            }

            #endregion
            #region Sending E-Mail

            SmtpClient client = new SmtpClient();
            Email email = EmailManager.GetByID(mailid);
            client.Host = emailSetting.Host;
            client.Port = emailSetting.Port;
            client.EnableSsl = emailSetting.EnableSSL;
            client.UseDefaultCredentials = emailSetting.UseCredential;
            if (emailSetting.UseCredential)
            {
                client.Credentials = new NetworkCredential(emailSetting.Username, emailSetting.Password);
            }
            MailMessage _mail = new MailMessage();
            _mail.Subject = email.Name;
            _mail.IsBodyHtml = true;
            _mail.From = _mail.Sender = new MailAddress(emailSetting.SernderAddress, emailSetting.SenderName);
            IList<EmailQueue> colEmails = null;
            colEmails = EmailQueueManager.GetAllPending();

            for (int i = 0; i < colEmails.Count; i++)
            {
                try
                {
                    _mail.Body = "";
                    _mail.Body = email.Details + EmailContext.GetTrackingCode(colEmails[i].ID.ToString());
                    _mail.To.Clear();
                    _mail.To.Add(new MailAddress(colEmails[i].ReciverAddress, colEmails[i].RecieverName));
                    client.Send(_mail);
                    _mail.Subject = email.Name;
                    colEmails[i].SendingStatus = DataLayer.Enums.RootEnums.SendingStatus.Sent;
                    colEmails[i].DeliveryStatus = DataLayer.Enums.RootEnums.DeliveryStatus.Unknown;
                    EmailQueueManager.Update(colEmails[i]);
                }
                catch (Exception ex)
                {
                    colEmails[i].SendingStatus = DataLayer.Enums.RootEnums.SendingStatus.failed;
                    colEmails[i].DeliveryStatus = DataLayer.Enums.RootEnums.DeliveryStatus.Failed;
                    EmailQueueManager.Update(colEmails[i]);
                    UtilitiesManager.WriteFile(ExpressoConfig.GeneralConfigElement.GetPhysicalLoggingPath, ex.ToString(), false, true);
                }

            }
            #endregion
        }
示例#5
0
        public IList<EmailQueue> Search(int mailid, int deliveryStatus, int sentStatus, string date, string recieveremail)
        {

            EmailQueue obj = null;

            IList<EmailQueue> colobj = null;
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = SELECTALLEmailQueueSearch;

            #region [Parameters]
            SqlParameter parameterds = new SqlParameter(PN_DELIVERYSTATUS, SqlDbType.Int);
            parameterds.Value = deliveryStatus;
            parameterds.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterds);

            SqlParameter parameterss = new SqlParameter(PN_SENDINGSTATUS, SqlDbType.Int);
            parameterss.Value = sentStatus;
            parameterss.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterss);

            SqlParameter parametersd = new SqlParameter(PN_SENTDATE, SqlDbType.NVarChar);
            parametersd.Value = date;
            parametersd.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parametersd);

            SqlParameter parameterre = new SqlParameter(PN_RECIVERADDRESS, SqlDbType.NVarChar);
            parameterre.Value = recieveremail;
            parameterre.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterre);

            SqlParameter parameterei = new SqlParameter(PN_MAILID, SqlDbType.Int);
            parameterei.Value = mailid;
            parameterei.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterei);
            #endregion;

            _connection.Open();
            try
            {
                using (_dtreader = _command.ExecuteReader())
                {
                    if (_dtreader != null && _dtreader.HasRows)
                    {
                        obj = new EmailQueue();
                        colobj = new List<EmailQueue>();
                        while (_dtreader.Read())
                        {
                            obj = GetEmailQueue(_dtreader, colobj);
                            GetEntityFromReader(_dtreader, obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                _dtreader.Close();
                _connection.Close();
            }

            return colobj;
        }
示例#6
0
 public EmailQueue GetEmailQueue(SqlDataReader _dtr, IList<EmailQueue> colobj)
 {
     EmailQueue obj = colobj.Where(t => t.ID == Convert.ToInt32(_dtr[CN_ID].ToString())).SingleOrDefault();
     if (null == obj)
     {
         obj = new EmailQueue();
         colobj.Add(obj);
     }
     return obj;
 }
示例#7
0
        public IList<EmailQueue> GetAllPending()
        {

            EmailQueue obj = null;

            IList<EmailQueue> colobj = new List<EmailQueue>();
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = SELECTALLEmailQueuePending;

            _connection.Open();
            try
            {
                using (_dtreader = _command.ExecuteReader())
                {
                    if (_dtreader != null && _dtreader.HasRows)
                    {
                        obj = new EmailQueue();
                        colobj = new List<EmailQueue>();
                        while (_dtreader.Read())
                        {
                            obj = GetEmailQueue(_dtreader, colobj);
                            GetEntityFromReader(_dtreader, obj);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                _dtreader.Close();
                _connection.Close();
            }

            return colobj;
        }
示例#8
0
 private void GetEntityFromReader(SqlDataReader _dtr, EmailQueue obj)
 {
     PopulateEmailQueue(_dtr, obj);
 }
示例#9
0
        public EmailQueue GetByID(int ID)
        {

            EmailQueue obj = null;
            _connection.ConnectionString = _ConnectionString;
            _command.Connection = _connection;
            _command.CommandType = CommandType.StoredProcedure;
            _command.CommandText = SELECTEmailQueue;

            #region [Parameters]
            SqlParameter parameterID = new SqlParameter(PN_ID, SqlDbType.Int);
            parameterID.Value = ID;
            parameterID.Direction = ParameterDirection.Input;
            _command.Parameters.Add(parameterID);
            #endregion;

            _connection.Open();
            try
            {
                using (_dtreader = _command.ExecuteReader())
                {
                    if (_dtreader != null && _dtreader.HasRows)
                    {
                        obj = new EmailQueue();
                        if (_dtreader.Read())
                            GetEntityFromReader(_dtreader, obj);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                _dtreader.Close();
                _connection.Close();
            }

            return obj;
        }
示例#10
0
        public static void Update(EmailQueue obj)
        {
            EmailQueueDataMapper objCaller = new EmailQueueDataMapper();

            objCaller.Update(obj);
        }
示例#11
0
        public static int Add(EmailQueue obj)
        {
            EmailQueueDataMapper objCaller = new EmailQueueDataMapper();

            return objCaller.Add(obj);
        }