예제 #1
0
        public MainWindow()
        {
            InitializeComponent();

            string textLogo = new DefaultSettings(true).TextLogo;

            Title += textLogo;
            LabelTextLogo.Content = textLogo;

            _senderInfo.GetScreens();

            DataContext = this;
        }
예제 #2
0
파일: Sender.cs 프로젝트: djserega/Helper
        internal bool SendMessage()
        {
            if (SenderInfo == null)
            {
                throw new NullReferenceException("Не заполнен объект отправки сообщения.");
            }

            DefaultSettings settings = new DefaultSettings();

            try
            {
                settings.GetDefaultSettings();
            }
            catch (Exception)
            {
                try
                {
                    settings.SetDefaultSettings();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return(false);
            }

            try
            {
                using (MailMessage mailMessage = new MailMessage()
                {
                    From = new MailAddress(settings.MailFrom),
                    Subject = SenderInfo.Subject,
                    Body = SenderInfo.Text
                })
                {
                    mailMessage.To.Add(new MailAddress(settings.MailTo));
                    mailMessage.Headers.Add("SenderApplication", "helper");

                    foreach (string fullName in SenderInfo.Screens)
                    {
                        mailMessage.Attachments.Add(new Attachment(fullName));
                    }

                    using (SmtpClient client = new SmtpClient(settings.Server, settings.Port)
                    {
                        //EnableSsl = true,
                        UseDefaultCredentials = true,
                        Timeout = 10 * 1000
                    })
                    {
                        client.Send(mailMessage);
                    }
                };
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }