Пример #1
0
        void SendInvitationMailForNew(List <Mantaemail> objemaillist, List <Mandrillaccount> allmandrillACC)
        {
            MantaemailRepository      mantaemailrepo = new MantaemailRepository();
            MandrillaccountRepository mandrillRepo   = new MandrillaccountRepository();
            //InvitationRepository invitationRepo = new InvitationRepository();
            List <int> ValidIds   = new List <int>();
            List <int> InvalidIds = new List <int>();
            int        p          = 0;

            try
            {
                foreach (Mantaemail email_item in objemaillist)
                {
                    try
                    {
                        Mandrillaccount mandrillACC = allmandrillACC[p];
                        string          SenderEmail = mandrillACC.UserName;
                        string          SenderPass  = mandrillACC.Password;
                        string          fromname    = RandomNameGenerator.CreateName().ToLower();
                        string[]        name        = Regex.Split(fromname, " ");
                        string          fname       = name[0].Substring(0, 1).ToUpper() + name[0].Substring(1, name[0].Length - 1);
                        string          lname       = name[1].Substring(0, 1).ToUpper() + name[1].Substring(1, name[1].Length - 1);
                        fromname = fname + " " + lname;
                        string rtn = MailSender.SendIvitationMailForNew(email_item.Name.Trim(), email_item.Email.Trim(), SenderEmail, SenderPass, fromname);
                        //string rtn4 = MailSender.SendIvitationMailForNew(email_item.Name.Trim(), "*****@*****.**", SenderEmail, SenderPass,fromname);
                        //string rtn1 = MailSender.SendIvitationMailForNew(email_item.Name.Trim(), "*****@*****.**", SenderEmail, SenderPass,fromname);
                        //string rtn2 = MailSender.SendIvitationMailForNew(email_item.Name.Trim(), "*****@*****.**", SenderEmail, SenderPass, fromname);
                        //string rtn4 = MailSender.SendIvitationMailForNew(email_item.Name.Trim(), "*****@*****.**", SenderEmail, SenderPass, fromname);
                        //string rtn3 = MailSender.SendIvitationMailForNew(email_item.Name.Trim(), "*****@*****.**", SenderEmail, SenderPass, fromname);

                        //string rtn = null;
                        if (rtn != null)
                        {
                            try
                            {
                                Console.WriteLine("<----------------------------------------------------------------->");
                                Console.WriteLine("<-------Mail Send to:" + email_item.Email + " By " + fromname + "--------->");
                                Console.WriteLine("<----------------------------------------------------------------->");
                                string[] mailinfo = Regex.Split(rtn, "####");

                                #region status set to 2 after success
                                ValidIds.Add(email_item.Id);
                                //mantaemailrepo.UpdateStatus2(email_item.Id);
                                #endregion

                                #region Increase the total no of mail sent from a mandrill account
                                mandrillACC.Total = mandrillACC.Total + 1;
                                mandrillRepo.UpdateMandrillAccount(mandrillACC.Id, mandrillACC.Total);
                                #endregion

                                //#region Insert Record after success
                                //Invitation invite = new Invitation();
                                //invite.InvitationBody = mailinfo[0];
                                //invite.Subject = mailinfo[1];
                                //invite.SenderName = "";
                                //invite.FriendEmail = mailinfo[4];
                                //invite.SenderEmail = mailinfo[3];
                                //invite.FriendName = mailinfo[2];
                                //invite.Status = "2";
                                //invite.SaveDate = DateTime.Now;
                                //invite.MandrillSendDate = DateTime.Now;
                                //invite.MandrillId = mandrillACC.Id;
                                //invitationRepo.Add(invite);
                                //#endregion
                            }
                            catch (Exception ex)
                            {
                                Console.Write(ex.StackTrace);
                            }
                        }
                        else
                        {
                            Console.WriteLine("<------------------------------------------------->");
                            Console.WriteLine("<-------Mail Failled to:" + email_item.Email + "--------->");
                            Console.WriteLine("<------------------------------------------------->");
                            InvalidIds.Add(email_item.Id);
                        }
                        p++;
                        if (p >= allmandrillACC.Count())
                        {
                            p = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            mantaemailrepo.UpdateStatusIsValid(InvalidIds);
            mantaemailrepo.UpdateStatus2Bulk(ValidIds);
        }