Example #1
0
        public SMTPListener(SMTPSettings settings)
        {
            this.settings = settings;

            this.portforwards = new List<SMTPRelayer>();
            this.client_listener = new TcpListener(IPAddress.Loopback, this.settings.LocalPort);
        }
Example #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;
            }
        }
Example #3
0
 public void UpdateSMTPSettings(SMTPSettings settings)
 {
     using (var db = new LiteDatabase(DatabasePath))
     {
         var settingsCollection = db.GetCollection <SMTPSettings>();
         settingsCollection.Update(settings);
     }
 }
Example #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); };
 }
 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);
 }
        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);
        }
Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #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);
            }
        }
Example #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");
            }
        }
Example #14
0
 public CredentialProvider(SMTPSettings settings)
 {
     this.settings = settings;
 }
Example #15
0
 public EmailServices(IOptions <SMTPSettings> smtpsettings)
 {
     _smtpsettings = smtpsettings.Value;
 }
Example #16
0
 public EmailService(IOptions <EmailSettings> emailSettings, IOptions <SMTPSettings> smtpSettings)
 {
     this.emailSettings = emailSettings.Value;
     this.smtpSettings  = smtpSettings.Value;
 }
 public EmailService(IOptions <SMTPSettings> appSettings)
 {
     _settings = appSettings.Value;
 }
 public EmailService(IOptions <SMTPSettings> appSettings, IToastNotification toastNotification)
 {
     _settings = appSettings.Value;
     this._toastNotification = toastNotification;
 }
Example #19
0
 public MailService(IOptions <SMTPSettings> smtpSettings, ILogger <MailService> logger)
 {
     _smtpSettings = smtpSettings.Value;
     _logger       = logger;
 }
Example #20
0
 private void Start()
 {
     this.smtpSettings = JsonConvert.DeserializeObject <SMTPSettings>(this.Text.text);
 }
Example #21
0
        public ResultReponse UpdateSMTPSettings(SMTPSettings SMTPSettings, UserInfo MyUserInfo)
        {
            UsersDbService m_UsersDbService = new UsersDbService();

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