Example #1
0
        //======================================================================================To send the email from email queue data=====================================================================
        /// <summary>
        /// To send the email from email queue data
        /// </summary>
        public static void SendEmailFromQueue()
        {
            Console.WriteLine("SendEmailFromQueue()");
            try
            {
                EmailQueueRepositery _EmailQueueRepositeryObject = new EmailQueueRepositery();
                EmailLogsRepositery  _EmailLogsRepositeryObject  = new EmailLogsRepositery();
                Email       _EmailObject = new Email();
                EmailQueue  item         = new EmailQueue();
                string      hostname     = Dns.GetHostName();
                IPAddress[] iPAddress    = Dns.GetHostAddresses(hostname);
                string      ip           = iPAddress[1].ToString();
                int         success      = 0;


                Console.WriteLine("Send email from email queue is executing...");
                //read emails details from emailqueue
                item = _EmailQueueRepositeryObject.GetTopEmailQueueDetail();

                if (item != null)    //emailQueueList.Count() != 0
                {
                    //set deleted is 1 in emailqueue
                    //_EmailQueueRepositeryObject.UpdateIsDeletedTrue(item);

                    //read tries from EmailQueue table
                    //int tries = _EmailQueueRepositeryObject.GetTries(item);
                    int tries = 0;

                    while (tries <= 5)
                    {
                        //send email
                        success = _EmailObject.SendEmail(item.FromAddress, item.ToAddress, item.Subject, item.Body);

                        if (success == 1)
                        {
                            //insert email details into emaillogs status as success
                            _EmailLogsRepositeryObject.InsertEmaillogs(item.FromAddress, item.ToAddress, item.Subject, item.Body, "mail.clanstech.com", ip, "Success");
                            //delete email detail from email queue
                            _EmailQueueRepositeryObject.DeletedFromEmailQueue(item);
                            Console.WriteLine("Email sent successfull to : " + item.ToAddress);
                            break;
                        }
                        else
                        {
                            //set deleted is 0 in emailqueue
                            //_EmailQueueRepositeryObject.UpdateIsDeletedFalse(item);
                            //increment tries into emailqueue
                            _EmailQueueRepositeryObject.IncrementTries(item);
                            Console.WriteLine("Email sending fail to : " + item.ToAddress);
                        }
                        //read tries from EmailQueue table
                        tries = _EmailQueueRepositeryObject.GetTries(item);
                        Console.WriteLine("Incrementing try");
                    }
                    if (tries >= 6)
                    {
                        //insert email details into emaillogs status as fail
                        _EmailLogsRepositeryObject.InsertEmaillogs(item.FromAddress, item.ToAddress, item.Subject, item.Body, "mail.clanstech.com", ip, "Fail");
                        //delete email detail from email queue
                        _EmailQueueRepositeryObject.DeletedFromEmailQueue(item);
                        Console.WriteLine("Email sending  fail to : " + item.ToAddress);
                    }
                }
                else
                {
                    Console.WriteLine("Email Queue is empty...");
                }
            }
            catch (Exception ex)
            {
                try
                {
                    ExceptionLogsRepositery _ExceptionLogsRepositeryObject = new ExceptionLogsRepositery();
                    MethodBase site = MethodBase.GetCurrentMethod();
                    string     url  = "";// Request.Url.ToString();
                    _ExceptionLogsRepositeryObject.InsertException(ex, url, site.Name);
                }
                catch (Exception exnew)
                {
                    Console.WriteLine("****Parent");
                    Console.WriteLine("Message : " + ex.Message);
                    Console.WriteLine("StackTrace : " + ex.StackTrace);
                    Console.WriteLine("Data : " + ex.Data);
                    Console.WriteLine("Source : " + ex.Source);
                    Console.WriteLine("****Child");
                    Console.WriteLine("Message : " + exnew.Message.ToString());
                    Console.WriteLine("StackTrace : " + exnew.StackTrace);
                    Console.WriteLine("Data : " + exnew.Data);
                    Console.WriteLine("Source : " + exnew.Source);
                }
            }
        }
Example #2
0
        //To send the email from email queue data
        public static void SendEmailFromQueue()
        {
            EmailQueueRepositery    _EmailQueueRepositeryObject    = new EmailQueueRepositery();
            EmailLogsRepositery     _EmailLogsRepositeryObject     = new EmailLogsRepositery();
            ExceptionLogsRepositery _ExceptionLogsRepositeryObject = new ExceptionLogsRepositery();
            Email      _EmailObject = new Email();
            EmailQueue item         = new EmailQueue();
            string     hostname     = Dns.GetHostName();

            IPAddress[] iPAddress = Dns.GetHostAddresses(hostname);
            string      ip        = iPAddress[1].ToString();
            int         success   = 0;

            try
            {
                //read emails details from emailqueue
                item = _EmailQueueRepositeryObject.GetTopEmailQueueDetail();

                if (item != null)    //emailQueueList.Count() != 0
                {
                    //set deleted is 1 in emailqueue
                    //_EmailQueueRepositeryObject.UpdateIsDeletedTrue(item);

                    //read tries from EmailQueue table
                    //int tries = _EmailQueueRepositeryObject.GetTries(item);
                    int tries = 0;

                    while (tries <= 5)
                    {
                        //send email
                        success = _EmailObject.SendEmail(item.FromAddress, item.ToAddress, item.Subject, item.Body);

                        if (success == 1)
                        {
                            //insert email details into emaillogs status as success
                            _EmailLogsRepositeryObject.InsertEmaillogs(item.FromAddress, item.ToAddress, item.Subject, item.Body, "mail.clanstech.com", ip, "Success");
                            //delete email detail from email queue
                            _EmailQueueRepositeryObject.DeletedFromEmailQueue(item);
                            break;
                        }
                        else
                        {
                            //set deleted is 0 in emailqueue
                            //_EmailQueueRepositeryObject.UpdateIsDeletedFalse(item);
                            //increment tries into emailqueue
                            _EmailQueueRepositeryObject.IncrementTries(item);
                        }
                        //read tries from EmailQueue table
                        tries = _EmailQueueRepositeryObject.GetTries(item);
                    }
                    if (tries > 6)
                    {
                        //insert email details into emaillogs status as fail
                        _EmailLogsRepositeryObject.InsertEmaillogs(item.FromAddress, item.ToAddress, item.Subject, item.Body, "mail.clanstech.com", ip, "Fail");
                        //delete email detail from email queue
                        _EmailQueueRepositeryObject.DeletedFromEmailQueue(item);
                    }
                }
            }
            catch (Exception ex)
            {
                MethodBase site = MethodBase.GetCurrentMethod();
                string     url  = "";// Request.Url.ToString();
                _ExceptionLogsRepositeryObject.InsertException(ex, url, site.Name);
            }
        }