Пример #1
0
 public FileSender(string ourMail, string targetMail, ISmtpHandler mailSender, ISendingFileFactory creator)
 {
     this.OurMail             = ourMail;
     this.TargetMail          = targetMail;
     this._mailSender         = mailSender;
     this._sendingFileCreator = creator;
 }
Пример #2
0
        /// <summary>
        /// Creates a new SimpleServer that listens on a specific
        /// port for connections and passes them to the specified delagat
        /// </summary>
        /// <param name="domain">
        /// The domain name this server handles mail for.  This does not have to
        /// be a valid domain name, but it will be included in the Welcome Message
        /// and HELO response.
        /// </param>
        /// <param name="port">The port to listen on.</param>
        /// <param name="recipientFilter">
        /// The IRecipientFilter implementation is responsible for 
        /// filtering the recipient addresses to determine which ones
        /// to accept for delivery.
        /// </param>
        /// <param name="handler">
        /// Handler for inbound message once it has been recieved from the sender.
        /// </param>
        /// <param name="logger"> </param>
        public SmtpServer(
            Action<MailMessage> handler,
            int port = 25,
            string domain = null, 
            Func<SmtpContext, MailAddress, bool> recipientFilter = null, 
            ILog logger = null)
		{
			_port = port;
            _handler = new SmtpHandler(
                domain ?? Environment.MachineName,
                handler,
                recipientFilter ?? ((context, address) => 
                    domain == null || domain.Equals(address.Host)),
                logger ?? new NullLogger());
        }
Пример #3
0
 /// <summary>
 /// Creates a new SimpleServer that listens on a specific
 /// port for connections and passes them to the specified delagat
 /// </summary>
 /// <param name="domain">
 /// The domain name this server handles mail for.  This does not have to
 /// be a valid domain name, but it will be included in the Welcome Message
 /// and HELO response.
 /// </param>
 /// <param name="port">The port to listen on.</param>
 /// <param name="recipientFilter">
 /// The IRecipientFilter implementation is responsible for
 /// filtering the recipient addresses to determine which ones
 /// to accept for delivery.
 /// </param>
 /// <param name="handler">
 /// Handler for inbound message once it has been recieved from the sender.
 /// </param>
 /// <param name="logger"> </param>
 public SmtpServer(
     Action <MailMessage> handler,
     int port      = 25,
     string domain = null,
     Func <SmtpContext, MailAddress, bool> recipientFilter = null,
     ILog logger = null)
 {
     _port    = port;
     _handler = new SmtpHandler(
         domain ?? Environment.MachineName,
         handler,
         recipientFilter ?? ((context, address) =>
                             domain == null || domain.Equals(address.Host)),
         logger ?? new NullLogger());
 }
Пример #4
0
        private static FileHandler InstantiateDefaultFileHandler()
        {
            AppSettingsReader appSettingsReader = new AppSettingsReader();

            string ourMail    = (string)appSettingsReader.GetValue("OurMailAddress", typeof(string));
            string targetMail = (string)appSettingsReader.GetValue("TargetMailAddress", typeof(string));

            ISmtpHandler        smtpHandler = GetSmtpHandler(appSettingsReader);
            ISendingFileFactory fileFactory = new SendingFileFactory();

            FileSender sender = new FileSender(ourMail, targetMail, smtpHandler, fileFactory);

            IFileManipulator manipulator = new FileManipulator();

            string mailToSendFolderPath  = (string)appSettingsReader.GetValue("MailToSendFP", typeof(string));
            string invalidMailFolderPath = (string)appSettingsReader.GetValue("InvalidMailFP", typeof(string));

            // NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            NotifyFilters notifyFilter = (NotifyFilters)appSettingsReader.GetValue("NotifyFilter", typeof(int));
            string        filter       = (string)appSettingsReader.GetValue("Filter", typeof(string));
            IFileWatcher  watcher      = new FileWatcher(mailToSendFolderPath, filter, notifyFilter, manipulator);

            ILog logger = LogManager.GetLogger(typeof(FileHandler));

            FileHandler result = new FileHandler(mailToSendFolderPath, invalidMailFolderPath, watcher, manipulator, sender, logger);

            return(result);

            SmtpHandler GetSmtpHandler(AppSettingsReader settingsReader)
            {
                string             host            = (string)settingsReader.GetValue("Host", typeof(string));
                int                port            = (int)settingsReader.GetValue("Port", typeof(int));
                SmtpDeliveryMethod method          = (SmtpDeliveryMethod)settingsReader.GetValue("SMTPDeliveryMethod", typeof(int));
                string             ourMailPassword = (string)settingsReader.GetValue("OurMailPassword", typeof(string));
                bool               enableSsl       = (bool)settingsReader.GetValue("EnableSSL", typeof(bool));

                return(new SmtpHandler(host, port, method, new NetworkCredential(ourMail, ourMailPassword), enableSsl));
            }
        }