Ejemplo n.º 1
0
        private void Listener()
        {
            try
            {
                var domain    = "testdomain.com";
                var processor = new SmtpHandler(domain, x => _messageSpool.Enqueue(x), (context, address) => address.Host == domain, new NullLogger());

                _listener = new TcpListener(EndPoint);
                _listener.Start();
                Console.WriteLine("Socket listener started...");
                var clientSocket = _listener.AcceptSocket();
                processor.HandleConnection(clientSocket);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception in Listener: " + exception);
                Console.WriteLine(exception.StackTrace);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SmtpHandler smtpHandler = new SmtpHandler("smtp.gmail.com", 587, "*****@*****.**", "aq1212qa", "MF", true);
            MailHandler mailHandler = new MailHandler(smtpHandler);

            Console.Write("Select mode of mail subject and body selecting (type/file): ");

            if (Console.ReadLine() == "type")
            {
                Console.Write("Enter a mail subject: ");
                mailHandler.Subject = Console.ReadLine();
                Console.Write("Enter a mail body: ");
                mailHandler.Body = Console.ReadLine();
                Console.Write("Enter path to attachment file (or skip this step): ");
                string pathToAttachmentFile = Console.ReadLine();

                if (!string.IsNullOrEmpty(pathToAttachmentFile))
                {
                    mailHandler.PathToAttachmentFile = pathToAttachmentFile;
                }
            }
            else
            {
                CsvFile subjectAndBodyFile = new CsvFile(';');

                if (!subjectAndBodyFile.ReadFile(@"input\mail-subject-and-body.csv", out string r2))
                {
                    Console.WriteLine(r2);
                    return;
                }

                mailHandler.Subject = subjectAndBodyFile.Rows.First()[0];
                mailHandler.Body    = subjectAndBodyFile.Rows.First()[1];
                mailHandler.PathToAttachmentFile = subjectAndBodyFile.Rows.First()[2];
            }

            Console.WriteLine("Emails sending...");
            mailHandler.LoadEmailsFromCsvFile(@"input\emails.csv");
            mailHandler.GenerateMailRepository();
            mailHandler.StartSendingProcess(false);
            Console.WriteLine("Okay, I`m done!");
        }