Popular Posts
Enable edit option in Shutter in Linux sudo apt-get install libgoo-canvas-perl Reference: How To Fix Disabled Edit Option In Shutter in Linux Mint CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
Blog Archive
Stats
Send mail tool
using System;
using System.Net.Mail;
using System.Net;

namespace Bruce.Mail
{
    public class MailFactory
    {
        private static SmtpClient client;
        public static void SetSmtp(string smtpHost, int smtpPort, string username, string password)
        {
            SetSmtp(smtpHost, smtpPort);
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(username, password);
        }
        public static void SetSmtp(string smtpHost, int smtpPort)
        {
            client = new SmtpClient(smtpHost, smtpPort);
        }
        public static void SetSmtp()
        {
            client = new SmtpClient();
        }

        private MailMessage message;
        public MailMessage Message
        {
            get { return this.message; }
        }

        public MailFactory()
        {
            this.message = new MailMessage();
        }

        public MailFactory(MailAddress from, MailAddress to)
        {
            this.message = new MailMessage(from, to);
        }

        public MailFactory(string fromName, string fromAddress, string toName, string toAddress)
        {
            MailAddress from = string.IsNullOrEmpty(fromName) ? new MailAddress(fromAddress) : new MailAddress(fromAddress, fromName);
            MailAddress to = string.IsNullOrEmpty(toName) ? new MailAddress(toAddress) : new MailAddress(toAddress, toName);
            this.message = new MailMessage(from, to);
        }

        public void Write(string subject, string body)
        {
            this.message.Subject = subject;
            this.message.IsBodyHtml = false;
            this.message.Body = body;
            this.Send();
        }

        public Exception Send()
        {
            try
            {
                if (client == null) SetSmtp();
                client.Send(this.message);
                return null;
            }
            catch (Exception ex)
            {
                return ex;
            }
        }
    }
}
using System;
using System.Net.Mail;
using System.Collections.Generic;
using System.Threading;

namespace Bruce.Mail
{
    public abstract class PostMan
    {
        private static Queue<MailAddress> Recivers = new Queue<MailAddress>();
        public static void AddReciver(MailAddress address)
        {
            Recivers.Enqueue(address);
        }
        public static void AddReciver(string address)
        {
            Recivers.Enqueue(new MailAddress(address));
        }

        private int checkInterval;
        public int CheckInterval
        {
            get { return this.checkInterval; }
            set { this.checkInterval = value; }
        }
        private bool flag = true;
        public bool Flag
        {
            get { return this.flag; }
            set { this.flag = value; }
        }

        public void Work()
        {
            while (Flag)
            {
                if (Recivers.Count == 0)
                {
                    Thread.Sleep(30000);
                }
                else
                {
                    MailAddress to = Recivers.Dequeue();
                    Deliver(to);
                }
            }
        }

        abstract void Deliver(MailAddress to);
    }
}