示例#1
0
        public void AddToMailerQueue(string ConStrings)
        {
            //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "Mail Process Started");
            try
            {
                #region get Mailer List

                Global global = new Global(ConStrings);

                MailerList = Global.RetrieveFromDB(ConStrings);
                //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "Retrive DBConnection Started");
                if (MailerList.Count > 0)
                {
                    //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "Mail Count " + MailerList.Count);
                    for (int i = 0; i < MailerList.Count; i++)
                    {
                        try
                        {
                            //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "In Loop 1 :" + i);
                            if (MailerList[i]._Smtp != null)
                            {
                                //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "In Loop 2 :" + i);

                                isMailsent = Global.SendEmail(MailerList[i]._Smtp, MailerList[i]._ToEmail, MailerList[i]._TikcketMailSubject, MailerList[i]._TicketMailBody,
                                                              string.IsNullOrEmpty(MailerList[i]._UserCC) ? null : MailerList[i]._UserCC.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                                                              string.IsNullOrEmpty(MailerList[i]._UserBCC) ? null : MailerList[i]._UserBCC.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                                                              MailerList[i]._TenantID, ConStrings);
                                //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "In Loop 3 :" + i);
                                if (isMailsent)
                                {
                                    //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "Mail Sent:" + isMailsent);
                                    successcount++;
                                    MailSuccessList.Add(MailerList[i]._MailID);
                                }
                                else
                                {
                                    failcount++;
                                }
                                //errorlogs.SendErrorToText(new NullReferenceException("Student object is null."), ConStrings, "Mail Sending status Fail Cnt : " + failcount + "Success Cnt :" + successcount);
                            }
                            else
                            {
                                smtperrorcount++;
                            }
                        }
                        catch (Exception ex)
                        {
                            errorlogs.SendErrorToText(ex, ConStrings);
                        }
                    }

                    if (MailSuccessList.Count > 0)
                    {
                        updatecount = Global.UpdateMailerQue(string.Join(",", MailSuccessList), ConStrings);
                        //errorlogs.SendErrorToText(null, ConStrings, "Mailer count updated in DB");
                    }

                    ConsoleMsg += "Mail sent SuccesFully for " + successcount + " records \n";
                    ConsoleMsg += "Mail Failed for " + failcount + " records \n";
                    ConsoleMsg += "Mail Failed due to SMTP error for " + smtperrorcount + " records \n";

                    //errorlogs.SendErrorToText(null, ConStrings, "Mailer Process complete");
                }


                #endregion
            }
            catch (Exception ex)
            {
                errorlogs.SendErrorToText(ex, ConStrings);
            }
        }