Ejemplo n.º 1
0
        public SMTPListener(SMTPSettings settings)
        {
            this.settings = settings;

            this.portforwards = new List<SMTPRelayer>();
            this.client_listener = new TcpListener(IPAddress.Loopback, this.settings.LocalPort);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SMTPSettings settings;
            FileInfo defaultsettings = new FileInfo("settings.cfg");
            if (defaultsettings.Exists)
            {
                settings = SMTPSettings.Load(defaultsettings.FullName);

                var smtplistener = new SMTPListener(settings);
                smtplistener.Start();

                Console.WriteLine("Started...");
                Console.ReadKey();

                smtplistener.Dispose();
            }
            else
            {
                Console.WriteLine("Created settings.cfg.");
                Console.WriteLine("Edit this file to customize.");
                settings = new SMTPSettings()
                {
                    LocalPort = 25,
                    Recipient ="*****@*****.**",
                    RemoteAddress = "smtp.com",
                    RemotePort = 25,
                    Sender = "*****@*****.**"
                };
                settings.Save(defaultsettings.FullName);
                return;
            }
        }
Ejemplo n.º 3
0
 public void UpdateSMTPSettings(SMTPSettings settings)
 {
     using (var db = new LiteDatabase(DatabasePath))
     {
         var settingsCollection = db.GetCollection <SMTPSettings>();
         settingsCollection.Update(settings);
     }
 }
Ejemplo n.º 4
0
 public MailEasy(SMTPSettings smtpSettings)
 {
     _SMTPSettings = smtpSettings;
     //Preparación para Secure Socket Layer
     // accept all SSL certificates (in case the server supports STARTTLS)
     smtpClient.ServerCertificateValidationCallback += (
         object sender,
         X509Certificate cert,
         X509Chain chain,
         SslPolicyErrors sslPolicyErrors) =>
     { Console.WriteLine(cert.Subject); return(true); };
 }
Ejemplo n.º 5
0
 public Email()
 {
     this._format = new MailFormatTXT();
     this._conf   = new SMTPSettings()
     {
         ServerName = "smtp.gmail.com",
         Password   = "******",
         UserName   = "******"
     };
     this._mail       = new Mail(_conf);
     this._maiMessage = new MailMessage(_format);
 }
Ejemplo n.º 6
0
        public static SMTPSettings Get()
        {
            var settings = new SMTPSettings
            {
                url      = Base.GetSettingValue("smtpUrl"),
                port     = int.Parse(Base.GetSettingValue("smtpPort")),
                login    = Base.GetSettingValue("smtpUser"),
                password = Base.GetSettingValue("smtpPassword"),
                alias    = Base.GetSettingValue("smtpAlias"),
                ssl      = Base.GetSettingValue("smtpSsl").Equals("true", System.StringComparison.InvariantCultureIgnoreCase)
            };

            return(settings);
        }
Ejemplo n.º 7
0
        public SMTPRelayer(TcpClient tcpClient, SMTPSettings settings)
        {
            this.settings = settings;
            Console.WriteLine("Connected... {0}", tcpClient.GetHashCode());

            this.client_tcp = tcpClient;
            this.client_Stream = tcpClient.GetStream();

            this.server_tcp = new TcpClient(settings.RemoteAddress, settings.RemotePort);
            this.server_Stream = server_tcp.GetStream();

            this.readthread = new Thread(new ThreadStart(Read));
            this.writethread = new Thread(new ThreadStart(Write));
        }
Ejemplo n.º 8
0
        public SMTPSettings GetCurrentSetting()
        {
            var session      = Common.Session.DatabaseConnection;
            var mailSettings = new SMTPSettings();

            mailSettings.DefaultFromAddress = FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_DefaultFromAddress") == null? string.Empty: FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_DefaultFromAddress").Value;
            mailSettings.Host     = FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Host") == null?string.Empty: FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Host").Value;
            mailSettings.Port     = FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Port") == null? 0 : int.Parse(FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Port").Value);
            mailSettings.Username = FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Username") == null? string.Empty: FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Username").Value;
            mailSettings.Password = FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Password") == null ? string.Empty: FamiHub.Crud.GetById <Models.Core.Property, string>("MailSetting_Password").Value;

            session.Close();

            return(mailSettings);
        }
Ejemplo n.º 9
0
        public void SendMail(MailProperties mailRequest, SMTPSettings smtp)
        {
            MailMessage objeto_mail = new MailMessage();
            SmtpClient  client      = new SmtpClient();

            client.Port                  = smtp.Port;
            client.Host                  = smtp.Host;
            client.Timeout               = 10000;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new System.Net.NetworkCredential(smtp.Username, smtp.Password);
            objeto_mail.From             = new MailAddress(smtp.DefaultFromAddress);
            objeto_mail.To.Add(new MailAddress(mailRequest.DestinationEmailAddress));
            objeto_mail.Subject = mailRequest.Subject;
            objeto_mail.Body    = "<p>" + mailRequest.Body + "</p>";
            client.Send(objeto_mail);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Validate SMTP Settings
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="smtpSection"></param>
        /// <returns></returns>
        public static HttpResponseMessage ValidateSMTPSettings(SMTPSettings settings, SmtpSection smtpSection)
        {
            try
            {
                if (settings.NotificationsEnabled ?? false)
                {
                    NotificationService.ErrorNotification(smtpSection, settings.SendTo);
                }
            }
            catch (Exception exception)
            {
                logger.Fatal($"There was an error sending a test email to {settings.SendTo} from {smtpSection.From}", exception);
                return(new HttpResponseMessage(HttpStatusCode.ExpectationFailed));
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Ejemplo n.º 11
0
        public SMTPSettings GetSMTPSettings()
        {
            using (var db = new LiteDatabase(DatabasePath))
            {
                var settingsCollection = db.GetCollection <SMTPSettings>();

                var settings = settingsCollection.FindAll().FirstOrDefault();
                if (settings == null)
                {
                    settings = new SMTPSettings()
                    {
                        Id = 1
                    };

                    settingsCollection.Insert(settings);
                }

                return(settings);
            }
        }
Ejemplo n.º 12
0
        public static bool SendEmail(SMTPSettings smtpSettings, string email)
        {
            if (smtpSettings == null || !smtpSettings.Enabled)
            {
                return(false);
            }

            var smptClient = new SmtpClient(smtpSettings.ServerName, smtpSettings.Port)
            {
                Credentials = new NetworkCredential(smtpSettings.Username, smtpSettings.Password),
                EnableSsl   = true
            };

            var message = new MailMessage(smtpSettings.Username, email);

            message.Subject = smtpSettings.EmailSubject;
            message.Body    = smtpSettings.EmailBody;
            smptClient.Send(message);
            return(true);
        }
        private void BtnSaveSMTP_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var smtpSettings = new SMTPSettings
                {
                    Id           = 1,
                    Password     = tbxPassword.Password,
                    Port         = Int32.Parse(tbxPortNumber.Text),
                    ServerName   = tbxServerName.Text,
                    Username     = tbxUsername.Text,
                    EmailSubject = tbxEmailSubject.Text,
                    EmailBody    = new TextRange(rtbEmailBody.Document.ContentStart, rtbEmailBody.Document.ContentEnd).Text,
                    Enabled      = cbxSMTPEnabled.IsChecked.GetValueOrDefault()
                };

                databaseService.UpdateSMTPSettings(smtpSettings);
                MessageBox.Show("SMTP Settings Updated", "SMTP Settings Success");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Issue while updating SMTP Settings: {ex.Message}", "SMTP Settings Error");
            }
        }
Ejemplo n.º 14
0
 public CredentialProvider(SMTPSettings settings)
 {
     this.settings = settings;
 }
Ejemplo n.º 15
0
 public EmailServices(IOptions <SMTPSettings> smtpsettings)
 {
     _smtpsettings = smtpsettings.Value;
 }
Ejemplo n.º 16
0
 public EmailService(IOptions <EmailSettings> emailSettings, IOptions <SMTPSettings> smtpSettings)
 {
     this.emailSettings = emailSettings.Value;
     this.smtpSettings  = smtpSettings.Value;
 }
Ejemplo n.º 17
0
 public EmailService(IOptions <SMTPSettings> appSettings)
 {
     _settings = appSettings.Value;
 }
Ejemplo n.º 18
0
 public EmailService(IOptions <SMTPSettings> appSettings, IToastNotification toastNotification)
 {
     _settings = appSettings.Value;
     this._toastNotification = toastNotification;
 }
Ejemplo n.º 19
0
 public MailService(IOptions <SMTPSettings> smtpSettings, ILogger <MailService> logger)
 {
     _smtpSettings = smtpSettings.Value;
     _logger       = logger;
 }
Ejemplo n.º 20
0
 private void Start()
 {
     this.smtpSettings = JsonConvert.DeserializeObject <SMTPSettings>(this.Text.text);
 }
Ejemplo n.º 21
0
        public ResultReponse UpdateSMTPSettings(SMTPSettings SMTPSettings, UserInfo MyUserInfo)
        {
            UsersDbService m_UsersDbService = new UsersDbService();

            return(m_UsersDbService.UpdateSMTPSettings(SMTPSettings, MyUserInfo));
        }