Example #1
0
        /// <summary>
        /// Заполнение именами стандартных переменных
        /// </summary>
        void FillStdOptions()
        {
            MailSrv = new MailParams();
            DateOptions = new List<string> { "d", "dd" ,"ddd","dddd",
                "f","ff","fff","ffff","fffff","ffffff",
            "F","FF","FFF","FFFF","FFFFF","FFFFFF","FFFFFFF","g", "gg",
            "h", "hh",
            "H","HH",
            "K", "m","mm",
            "M","MM","MMM","MMMM",
            "s","ss","t","tt",
            "y","yy","yyy","yyyy","yyyyy",
            "z","zz","zzz",
            "yyMMdd","yyyyMM","HHmm"};

            FileOptions=new List<string>{Const.FileOpt.ListFileName, Const.FileOpt.ListFullFileName,Const.FileOpt.FullFileName,
                Const.FileOpt.FileName,Const.FileOpt.FileWithoutExt,Const.FileOpt.ExtFile,Const.FileOpt.Nalog,Const.FileOpt.FileContent,
                Const.FileOpt.TruncFileName8d3,Const.FileOpt.TruncFileWithoutExt,Const.FileOpt.TruncExtFile};

            //CoverKeys = new List<string> { "S", "Act", "CONTAIN", "Exclude", "INC" };

            //CoverKeys = new List<string> { "S",  "CONTAIN", "Exclude", "INC" };

            //CoverKeys = new List<string> { "S" };

            //CoverWords = new Dictionary<string, string>();

            Options = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            Options.Add("ComputerName", System.Environment.MachineName);
            Options.Add("MachineName", System.Environment.MachineName);
            Options.Add("UserName", System.Environment.UserName);
            Options.Add("NewLine", Environment.NewLine);
            Options.Add(Const.FileOpt.DefaultEncoding, "windows-1251"); // Кодировка по умолчанию
            // Каталог программы
            string RootFolder; // Каталог запуска программы
            //RootFolder = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
            RootFolder = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            Options.Add("FNRouterDir", RootFolder);
            RootFolder = Path.Combine(RootFolder, "tmp");
            Options.Add("FNRouterTempDir", RootFolder);

            // Добавление спец каталогов
            string[] FoldNames = Enum.GetNames(typeof(Environment.SpecialFolder));
            Environment.SpecialFolder enName;

            foreach (string foldName in FoldNames)
            {
                enName = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), foldName);
                Options.Add(foldName, Environment.GetFolderPath(enName));
            }
        }
Example #2
0
        /// <summary>
        /// Чтение настроек почты
        /// </summary>
        /// <param name="LDecoder"></param>
        /// <param name="ReadEmpty"></param>
        private void ReadMailSet(LineDecoder LDecoder, bool ReadEmpty)
        {
            string sValue;
            sValue = LDecoder.GetValue("MAILSRV");
            if (ReadEmpty) this.MailSrv.MailSrv = sValue;
            else
            {
                if (!String.IsNullOrEmpty(sValue))
                    this.MailSrv.MailSrv = sValue;
            }
            sValue = LDecoder.GetValue("MAILFROM");
            if (ReadEmpty) this.MailSrv.MailFrom = sValue;
            else
            {
                if (!String.IsNullOrEmpty(sValue))
                    this.MailSrv.MailFrom = sValue;
            }

            sValue = LDecoder.GetValue("MAILPORT");
            if (ReadEmpty) MailSrv.SetPort(sValue);

            sValue = LDecoder.GetValue("MAILUSER");
            if (ReadEmpty) this.MailSrv.MailUser = sValue;
            else
            {
                if (!String.IsNullOrEmpty(sValue))
                    this.MailSrv.MailUser = sValue;
            }
            sValue = LDecoder.GetValue("MAILPASS");
            if (ReadEmpty) this.MailSrv.MailPass = sValue;
            else
            {
                if (!String.IsNullOrEmpty(sValue))
                    this.MailSrv.MailPass = sValue;
            }
        }
Example #3
0
        /// <summary>
        /// Отправка письма с вложением
        /// </summary>
        /// <param name="mparam"></param>
        /// <param name="MailTo"></param>
        /// <param name="Subj"></param>
        /// <param name="Mess"></param>
        /// <param name="FileName"></param>
        public static bool SendMail(MailParams MailSrv, string MailTo, string Subj, string Msg, string FileName,Logging Log)
        {
            //int tport, port = 25;
            bool ret;
            //Формирование письма
            MailMessage Message = new MailMessage();
            Attachment att = null; // Вложение
            Message.From = new MailAddress(MailSrv.MailFrom);
            Message.To.Add(MailTo);
            Message.Subject = Subj;
            Message.IsBodyHtml = false;
            Message.Body = Msg;
            // Вложение если есть
            if (!String.IsNullOrEmpty(FileName))
            {
                if (File.Exists(FileName))
                {
                    att = new Attachment(FileName);
                    Message.Attachments.Add(att);
                }
            }

            try
            {
                SmtpClient Smtp = new SmtpClient(MailSrv.MailSrv, MailSrv.MailPort);
                if (!String.IsNullOrEmpty(MailSrv.MailPass)) Smtp.Credentials = new NetworkCredential(MailSrv.MailUser, MailSrv.MailPass);
                Smtp.Send(Message);//отправка

                ret = true;
            }
            catch (SmtpFailedRecipientsException ESmtp)
            {
                //if (att != null) att.Dispose(); // Освобждение файла во вложении
                if (Log != null) Log.LogMessage(LogType.Error, "Ошибка отправки на почту. SmtpFailedRecipientsException. " + ESmtp.Message);
                ret = false;
            }
            catch (SmtpException ESmtp)
            {
                //if (att != null) att.Dispose(); // Освобждение файла во вложении
                switch (ESmtp.StatusCode)
                {
                    case SmtpStatusCode.GeneralFailure:
                        if (Log != null) Log.LogMessage(LogType.Error, "Ошибка отправки на почту. SmtpException. Сервер недоступен " + MailSrv.MailSrv + ". " + ESmtp.Message);
                        break;
                    default:
                        if (Log != null) Log.LogMessage(LogType.Error, "Ошибка отправки на почту. SmtpException. StatusCode=" + ESmtp.StatusCode.ToString() + ". Smtp host=" + MailSrv.MailSrv + ". " + ESmtp.Message);
                        break;
                }

                ret = false;
            }

            catch (Exception E)
            {
                //if (att != null) att.Dispose(); // Освобждение файла во вложении
                if (Log != null) Log.LogMessage(LogType.Error, "Ошибка отправки на почту. " + E.Message);
                ret = false;
            }
            finally
            {
                if (att != null) att.Dispose(); // Освобждение файла во вложении
                Message.Dispose(); // Освобождение сообщения

            }
            return ret;
        }