Пример #1
0
        public List <string> Send()
        {
            List <string> data   = new List <string>();
            Random        random = new Random();

            foreach (dynamic server in Servers)
            {
                try
                {
                    Pmta p = new Pmta((string)server.mainip, (string)server.password, (string)server.username, (int)server.port);
                    foreach (dynamic ip in server.ips)
                    {
                        string email_ip = ip.ip;
                        string domain   = ip.domain;
                        string rdns     = Text.Rdns(email_ip, domain);
                        string vmta_ip  = email_ip.Replace(':', '.');
                        string vmta     = Mta.ToLower() == "none" ? $"mta-{vmta_ip}" : (Mta == "vmta" ? $"vmta-{vmta_ip}-{Username}" : $"smtp-{vmta_ip}-{Username}");
                        string job      = $"0_CAMPAIGN-TEST_{Id}_{Username}";


                        string key         = Text.Adler32($"{Id}0");
                        string redirect    = Text.Base64Encode($"{Id}-0-{key}-{random.Next(1000, 99999)}");
                        string unsubscribe = Text.Base64Encode($"{Id}-0-{key}-{random.Next(1000, 99999)}");
                        string open        = Text.Base64Encode($"{Id}-0-{key}-{random.Next(1000, 99999)}");


                        foreach (string email in Emails)
                        {
                            string boundary  = Text.Random("[rndlu/30]");
                            string emailName = email.Split('@')[0];
                            string rp        = Text.Build_rp(Return_path, domain, rdns, emailName);
                            string hd        = Text.Build_header(Header, email_ip, domain, rdns, email, emailName, boundary);
                            hd = Text.Inject_header(hd, "t", Id.ToString(), Username, Convert.ToString(ip.ip), Convert.ToString(ip.idddomain));
                            string bd = Text.Build_body(Body, email_ip, domain, rdns, email, emailName, boundary);
                            bd      = Text.Generate_links(bd, redirect, unsubscribe, open);
                            Message = new Message(rp);
                            Message.AddData(hd + "\n" + bd);
                            Message.AddRecipient(new Recipient(email));
                            Message.VirtualMTA = vmta;
                            Message.JobID      = job;
                            Message.Verp       = false;
                            Message.Encoding   = Encoding.EightBit;
                            p.Send(Message);
                        }
                    }
                    data.Add($"SERVER {server.mainip} OK");
                    p.Close();
                }
                catch (Exception ex)
                {
                    data.Add($"ERROR SERVER {server.mainip} - {ex.Message}");
                    logger.Error(ex.Message);
                }
            }
            return(data);
        }
Пример #2
0
        public List <string> Send()
        {
            List <string> data = new List <string>();

            foreach (dynamic server in Servers)
            {
                try
                {
                    Pmta p = new Pmta((string)server.mainip, (string)server.password, (string)server.username, (int)server.port);
                    foreach (dynamic ip in server.ips)
                    {
                        string email_ip = ip.ip;
                        string domain   = ip.domain;
                        string rdns     = Text.Rdns(email_ip, domain);
                        string vmta_ip  = email_ip.Replace(':', '.');
                        string vmta     = Mta.ToLower() == "none" ? $"mta-{vmta_ip}" : (Mta == "vmta" ? $"vmta-{vmta_ip}-{Username}" : $"smtp-{vmta_ip}-{Username}");
                        string job      = $"0_GLOBAL-TEST_{Username}";

                        foreach (string email in Emails)
                        {
                            string emailName = email.Split('@')[0];
                            string rp        = Text.Build_rp(Return_path, domain, rdns, emailName);
                            string hd        = Text.Build_header(Header, email_ip, domain, rdns, email, emailName);
                            hd = Text.Inject_header(hd, "t", "0", Username, email_ip, Convert.ToString(ip.idddomain));
                            string bd = Text.Build_body(Body, email_ip, domain, rdns, email, emailName);
                            Message = new Message(rp);
                            Message.AddData(hd + "\n" + bd);
                            Message.AddRecipient(new Recipient(email));
                            Message.VirtualMTA = vmta;
                            Message.JobID      = job;
                            Message.Verp       = false;
                            Message.Encoding   = Encoding.EightBit;
                            p.Send(Message);
                        }
                    }
                    data.Add($"SERVER {server.mainip} OK");
                    p.Close();
                }
                catch (Exception ex)
                {
                    data.Add($"ERROR SERVER {server.mainip} - {ex.Message}");
                    logger.Error(ex.Message);
                }
            }
            return(data);
        }
Пример #3
0
        public List <string> Send()
        {
            List <string> Result   = new List <string>();
            Encryption    enc      = new Encryption(); //links encrpytion
            Campaign      campaign = new Campaign(Artisan);
            int           c_seed   = 0;


            dynamic cdata = campaign.Campaign_info(Id); //get info campaign

            if (cdata != null)
            {
                string   raw_rp           = Convert.ToString(cdata.return_path);
                string[] seed_emails      = Campaign.Convert_emails(Convert.ToString(cdata.email_test));
                string   raw_hd           = Text.Base64Decode(Convert.ToString(cdata.header));
                string   raw_bd           = Text.Base64Decode(Convert.ToString(cdata.body));
                var      servers          = Campaign.Bulk_split(Convert.ToString(cdata.ips));
                string   file             = Storage + "/" + Convert.ToString(cdata.send_file);
                string   platform         = Convert.ToString(cdata.platform);
                string   redirect_link    = Convert.ToString(cdata.redirect_link);
                string   unsubscribe_link = Convert.ToString(cdata.unsubscribe_link);

                int countlines = int.Parse(Convert.ToString(cdata.send_count));
                int countIps   = servers.Count;

                List <int> ipLimit = Campaign.DistributeInteger(countlines, countIps).ToList();

                List <Task> tasks = new List <Task>();
                for (int i = 0; i < countIps; i++)
                {
                    int current = i;
                    tasks.Add(
                        Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            if (ipLimit[current] > 0)
                            {
                                var details_server = campaign.Server_info(int.Parse(servers[current][4]));
                                if (details_server != null)
                                {
                                    Pmta p   = new Pmta(Convert.ToString(details_server.ip), Password);    //load pmta
                                    int skip = current == 0 ? 0 : ipLimit.Take(current).Sum();
                                    Console.WriteLine("skip " + skip);

                                    List <string[]> emails = File.ReadLines(file).Skip(skip).Take(ipLimit[current])
                                                             .Select(t => t.Trim().Split(','))
                                                             .Where(item => item.Length == 2)
                                                             .ToList();

                                    if (emails.Count > 0)
                                    {
                                        string email_ip = servers[current][0];
                                        string domain   = servers[current][1];
                                        string rdns     = Text.Rdns(email_ip, domain);
                                        string vmta_ip  = email_ip.Replace(':', '.');
                                        string vmta     = Mta.ToLower() == "none" ? $"mta-{vmta_ip}" : (Mta == "vmta" ? $"vmta-{vmta_ip}-{Username}" : $"smtp-{vmta_ip}-{Username}");
                                        string job      = $"{Id}";

                                        string rp       = Text.Build_rp(raw_rp, domain, rdns, "reply");
                                        Message message = new Message(rp);
                                        string header   = Text.Header_normal(raw_hd);
                                        message.AddMergeData(Text.Generate(header + "\n" + raw_bd));
                                        message.VirtualMTA = vmta;
                                        message.JobID      = Id.ToString();
                                        message.Verp       = false;
                                        message.Encoding   = Encoding.EightBit;

                                        foreach (string[] email in emails)
                                        {
                                            Recipient r = new Recipient(email[1]);
                                            //links
                                            r["red"]   = enc.Encrypt($"r!!{Id}!!{servers[current][2]}!!{servers[current][3]}!!{email[0]}!!{redirect_link}!!{platform}");
                                            r["unsub"] = enc.Encrypt($"u!!{Id}!!{servers[current][2]}!!{servers[current][3]}!!{email[0]}!!{unsubscribe_link}");
                                            r["opn"]   = enc.Encrypt($"o!!{Id}!!{servers[current][2]}!!{servers[current][3]}!!{email[0]}");
                                            r["out"]   = enc.Encrypt($"out!!{new Random().Next(5, 15)}");
                                            r["short"] = enc.Encrypt(email[0]);      //shortlink
                                            //header body
                                            r["pe"]       = $"n,{Id},{Username},{servers[current][2]},{servers[current][3]},{email[0]}";
                                            r["ip"]       = email_ip;
                                            r["domain"]   = domain;
                                            r["rdns"]     = rdns;
                                            r["name"]     = email[1].Split('@')[0];
                                            r["to"]       = email[1];
                                            r["date"]     = Text.GetRFC822Date();
                                            r["boundary"] = Text.Random("[rndlu/30]");
                                            r["*parts"]   = "1";

                                            message.AddRecipient(r);
                                            Interlocked.Increment(ref c_seed);

                                            if (Seed != 0 && c_seed % Seed == 0)
                                            {
                                                if (seed_emails.Length > 0)
                                                {
                                                    foreach (string test_email in seed_emails)
                                                    {
                                                        Recipient t = new Recipient(test_email);
                                                        //links
                                                        t["red"]   = enc.Encrypt($"r!!{Id}!!{servers[current][2]}!!{servers[current][3]}!!0!!{redirect_link}!!{platform}");
                                                        t["unsub"] = enc.Encrypt($"u!!{Id}!!{servers[current][2]}!!{servers[current][3]}!!0!!{unsubscribe_link}");
                                                        t["opn"]   = enc.Encrypt($"o!!{Id}!!{servers[current][2]}!!{servers[current][3]}!!0");
                                                        t["out"]   = enc.Encrypt($"out!!{new Random().Next(5, 10)}");
                                                        t["short"] = enc.Encrypt("0");      //shortlink
                                                        //header body
                                                        t["pe"]       = $"t,{Id},{Username},!!{servers[current][2]}!!{servers[current][3]}!!,0";
                                                        t["ip"]       = email_ip;
                                                        t["domain"]   = domain;
                                                        t["rdns"]     = rdns;
                                                        t["name"]     = test_email.Split('@')[0];
                                                        t["to"]       = email[1];
                                                        t["date"]     = Text.GetRFC822Date();
                                                        t["boundary"] = Text.Random("[rndlu/30]");
                                                        t["*parts"]   = "1";
                                                        message.AddRecipient(t);
                                                    }
                                                }
                                            }
                                        }
                                        p.Send(message);
                                        p.Close();
                                        //Task.Run(() => campaign.Campaign_update_send(Id, skip + ipLimit[current]));
                                        return;
                                    }
                                    else
                                    {
                                        logger.Error("Emails Empty" + Id);
                                        p.Close();
                                        return;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error($"ERR {ex.Message} -- {ex.StackTrace}");
                            Console.WriteLine($"ERR {ex.Message} -- {ex.StackTrace}");
                        }
                    })
                        );
                }

                Task.WaitAll(tasks.ToArray());
                campaign.Campaign_update_send(Id, countlines);
                campaign.Campaign_update_progress(Id, "start", true, 0);
                return(Result);
            }
            else
            {
                Result.Add("Campaign Not Found " + Id);
                logger.Debug("Campaign Not Found " + Id);
                campaign.Campaign_update_progress(Id, "start", true, 0);
                return(Result);
            }
        }
Пример #4
0
        public List <string> Send()
        {
            List <string> Result   = new List <string>();
            Campaign      campaign = new Campaign(Artisan);
            Message       message;
            int           c_seed = 0;
            Random        random = new Random();

            for (int i = 0; i < Loop; i++) //loop
            {
                Console.WriteLine("Loop : " + i);
                try
                {
                    dynamic cdata = campaign.Campaign_info(Id);
                    if (cdata != null)
                    {
                        string   raw_rp           = Convert.ToString(cdata.return_path) ?? "";
                        string[] seed_emails      = Campaign.Convert_emails(Convert.ToString(cdata.email_test));
                        string   raw_hd           = Text.Base64Decode(Convert.ToString(cdata.header));
                        string   raw_bd           = Text.Base64Decode(Convert.ToString(cdata.body));
                        var      servers          = Campaign.Convert_ips(Convert.ToString(cdata.ips));
                        string   file             = "/" + Convert.ToString(cdata.send_file);
                        string   platform         = Convert.ToString(cdata.platform);
                        string   redirect_link    = Convert.ToString(cdata.redirect_link);
                        string   unsubscribe_link = Convert.ToString(cdata.unsubscribe_link);

                        foreach (var server in servers)
                        {
                            var details_server = campaign.Server_info(int.Parse((string)server.Key));
                            if (details_server != null)
                            {
                                Pmta p = new Pmta(Convert.ToString(details_server.ip), Password); //load pmta
                                foreach (var ip in server.Value)
                                {
                                    var info_send = campaign.Campaign_send_info(Id);
                                    if (info_send != null)
                                    {
                                        int total_send = 0, value_to_send = 0; //check fraction
                                        int total_sended = int.Parse((string)info_send.send_progress);
                                        int file_count   = int.Parse((string)info_send.send_count);
                                        if (total_sended + Fraction >= file_count)
                                        {
                                            if (file_count - total_sended <= 0)
                                            {
                                                campaign.Campaign_update_progress(Id, "finish", true, 0);
                                                Result.Add("Campaign Ended" + Id);
                                                p.Close(); //close
                                                return(Result);
                                            }
                                            else
                                            {
                                                value_to_send = file_count - total_sended;
                                            }
                                        }
                                        else
                                        {
                                            value_to_send = Fraction;
                                        }

                                        //load emails

                                        List <string[]> emails = File.ReadLines(Storage + file).Skip(total_sended).Take(value_to_send)
                                                                 .Select(t => t.Trim().Split(','))
                                                                 .Where(item => item.Length == 2)
                                                                 .ToList();
                                        if (emails.Count > 0)
                                        {
                                            string email_ip = ip["ip"];
                                            string domain   = ip["domain"];
                                            string rdns     = Text.Rdns(email_ip, domain);
                                            string vmta_ip  = email_ip.Replace(':', '.');
                                            string vmta     = Mta.ToLower() == "none" ? $"mta-{vmta_ip}" : (Mta == "vmta" ? $"vmta-{vmta_ip}-{Username}" : $"smtp-{vmta_ip}-{Username}");
                                            string job      = $"{Id}";

                                            string rp = Text.Build_rp(raw_rp, domain, rdns, "reply");
                                            message = new Message(rp);
                                            string header = Text.Header_normal(raw_hd);
                                            message.AddMergeData(Text.Generate(header + "\n" + raw_bd));
                                            message.VirtualMTA = vmta;
                                            message.JobID      = Id.ToString();
                                            message.Verp       = false;
                                            message.Encoding   = Encoding.EightBit;

                                            foreach (string[] email in emails)
                                            {
                                                Recipient r = new Recipient(email[1]);
                                                //links
                                                string key = Text.Adler32($"{Id}{email[0]}");
                                                r["red"]   = Text.Base64Encode($"{Id}-{email[0]}-{key}-{random.Next(1000, 99999)}");
                                                r["unsub"] = Text.Base64Encode($"{Id}-{email[0]}-{key}-{random.Next(1000, 99999)}");
                                                r["opn"]   = Text.Base64Encode($"{Id}-{email[0]}-{key}-{random.Next(1000, 99999)}");

                                                //header body
                                                r["pe"]       = $"n,{Id},{Username},{ip["ip"]},{ip["idd"]},{email[0]}";
                                                r["ip"]       = email_ip;
                                                r["domain"]   = domain;
                                                r["rdns"]     = rdns;
                                                r["name"]     = email[1].Split('@')[0];
                                                r["to"]       = email[1];
                                                r["date"]     = Text.GetRFC822Date();
                                                r["boundary"] = Text.Random("[rndlu/30]");
                                                r["*parts"]   = "1";

                                                message.AddRecipient(r);

                                                total_send++;
                                                c_seed++;

                                                if (Seed != 0 && c_seed % Seed == 0)
                                                {
                                                    if (seed_emails.Length > 0)
                                                    {
                                                        foreach (string test_email in seed_emails)
                                                        {
                                                            Recipient t = new Recipient(test_email);
                                                            //links
                                                            string tkey = Text.Adler32($"{Id}0");
                                                            t["red"]   = Text.Base64Encode($"{Id}-0-{tkey}-{random.Next(1000, 99999)}");
                                                            t["unsub"] = Text.Base64Encode($"{Id}-0-{tkey}-{random.Next(1000, 99999)}");
                                                            t["opn"]   = Text.Base64Encode($"{Id}-0-{tkey}-{random.Next(1000, 99999)}");

                                                            //header body
                                                            t["pe"]       = $"t,{Id},{Username},{ip["ip"]},{ip["idd"]},0";
                                                            t["ip"]       = email_ip;
                                                            t["domain"]   = domain;
                                                            t["rdns"]     = rdns;
                                                            t["name"]     = test_email.Split('@')[0];
                                                            t["to"]       = email[1];
                                                            t["date"]     = Text.GetRFC822Date();
                                                            t["boundary"] = Text.Random("[rndlu/30]");
                                                            t["*parts"]   = "1";
                                                            message.AddRecipient(t);
                                                        }
                                                    }
                                                }
                                            }
                                            p.Send(message);
                                            Task.Run(() => campaign.Campaign_update_send(Id, total_send + total_sended));
                                        }
                                        else
                                        {
                                            Result.Add("Emails Empty" + Id);
                                            logger.Error("Emails Empty" + Id);
                                            campaign.Campaign_update_progress(Id, "start", true, 0);
                                            p.Close();
                                            return(Result);
                                        }
                                    }
                                    else
                                    {
                                        Result.Add("Cant get Send progress campaign" + Id);
                                        logger.Error("Cant get Send progress campaign" + Id);
                                        campaign.Campaign_update_progress(Id, "start", true, 0);
                                        p.Close();
                                        return(Result);
                                    }
                                    Thread.Sleep(Delay * 1000); //sleep delay
                                }
                                p.Close();                      //close pmta connection
                            }
                            else
                            {
                                Result.Add("Server Not Found " + server.Key);
                                logger.Error("Server Not Found " + server.Key);
                                campaign.Campaign_update_progress(Id, "start", true, 0);
                                return(Result);
                            }
                        }
                    }
                    else
                    {
                        Result.Add("Campaign Not Found " + Id);
                        logger.Debug("Campaign Not Found " + Id);
                        campaign.Campaign_update_progress(Id, "start", true, 0);
                        return(Result);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"ERR {ex.Message} -- {ex.StackTrace}");
                    logger.Error($"ERR {ex.Message} -- {ex.StackTrace}");
                }
                Thread.Sleep(Sleep * 1000);
            }

            campaign.Campaign_update_progress(Id, "start", true, 0);
            return(Result);
        }