Exemplo n.º 1
0
        public void SendMail()
        {
            QueueTest queueTest = new QueueTest();
            queueTest.BuildQueue();

            ILog log = new LogCounter();

            SendMailProcess sendMailProcess = new SendMailProcess(log);

            sendMailProcess.SetHostAndPort("smtp.hostname.com", 25);

            QueueProcess queueProcess = new QueueProcess();
            Queue queue = queueProcess.GetQueue();

            foreach(Recipient recipient in queue.RecipientData)
            {
                sendMailProcess.Send(
                    new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName),
                    new MailAddress[] { new MailAddress(recipient.Address, recipient.Name) },
                    queue.TicketData.Subject,
                    queue.TicketData.Body
                    );
            }
        }
Exemplo n.º 2
0
        public void Process()
        {
            if (processing || this.smtpServer == null) { return; }
            lock (lockObj)
            {
                processing = true;
            }

            QueueProcess queueProcess = new QueueProcess();

            int blockSleep = Convert.ToInt32(ConfigurationManager.AppSettings["BlockSleep"]);

            ClickOnceDMLib.Structs.Queue queue = queueProcess.GetQueue();

            if (queue != null)
            {
                InitSMTPServer();

                LogProcess.Info("In-Process Start");

                ILog log = new LogCounter(); // log interface

                foreach (Recipient recipient in queue.RecipientData)
                {
                    long baseTick = DateTime.Now.Ticks;

                    var smtp = from s1 in this.smtpServer
                               orderby s1.Weight ascending
                               select s1;

                    SMTPServer serverInfo = smtp.First();

                    SendMailProcess sendMailProcess = new SendMailProcess(log);

                    sendMailProcess.SetHostAndPort(serverInfo.Host, serverInfo.Port);

                    MailAddress mailAddress = null;

                    try
                    {
                        mailAddress = new MailAddress(recipient.Address.Trim(), recipient.Name);
                    }
                    catch (Exception ex)
                    {
                        LogProcess.Error(ex);
                        continue;
                    }

                    if (mailAddress != null)
                    {
                        sendMailProcess.Send(
                            new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName),
                            new MailAddress[] { mailAddress },
                            queue.TicketData.Subject,
                            queue.TicketData.Body
                            );

                        serverInfo.SetWeight(TimeSpan.FromTicks(DateTime.Now.Ticks - baseTick).Milliseconds);
                    }
                }

                log.Flush(); // write log

                LogProcess.Info("In-Process End");

                Thread.Sleep(blockSleep);
            }

            processing = false;
        }