Exemplo n.º 1
0
 //--- Methods ---
 public ISmtpClient CreateClient(SmtpSettings settings)
 {
     var client = new SmtpClient {
         Host = settings.Host,
         EnableSsl = settings.EnableSsl
     };
     _log.DebugFormat("SSL enabled: {0}", client.EnableSsl);
     if(settings.Port.HasValue) {
         client.Port = settings.Port.Value;
         _log.DebugFormat("using custom port: {0}", client.Port);
     }
     if(!string.IsNullOrEmpty(settings.AuthUser)) {
         _log.DebugFormat("using authentication user: {0}", settings.AuthUser);
         var credentials = new NetworkCredential(settings.AuthUser, settings.AuthPassword);
         client.Credentials = credentials;
     }
     return new SmtpClientWrapper(client);
 }
Exemplo n.º 2
0
 public ISmtpClient CreateClient(SmtpSettings settings)
 {
     Settings = settings;
     return Client;
 }
Exemplo n.º 3
0
 protected override Yield Stop(Result result)
 {
     _smtpSettings.Clear();
     _defaultSettings = null;
     yield return Coroutine.Invoke(base.Stop, new Result());
     result.Return();
 }
Exemplo n.º 4
0
        //--- Methods ---
        protected override Yield Start(XDoc config, ILifetimeScope container, Result result)
        {
            yield return Coroutine.Invoke(base.Start, config, new Result());
            _defaultSettings = new SmtpSettings { Host = config["smtp-host"].AsText };
            if(string.IsNullOrEmpty(_defaultSettings.Host)) {
                _defaultSettings.Host = "localhost";
            }
            _log.DebugFormat("Smtp Host: {0}", _defaultSettings.Host);

            // Note (arnec): ssl requires mono 2.0 and likely root certificate import via 'mozroots --import --ask-remove --machine'
            _defaultSettings.EnableSsl = config["use-ssl"].AsBool ?? false;
            if(config["smtp-port"].AsInt.HasValue) {
                _defaultSettings.Port = config["smtp-port"].AsInt.Value;
            }
            _defaultSettings.AuthUser = config["smtp-auth-user"].AsText;
            _defaultSettings.AuthPassword = config["smtp-auth-password"].AsText;
            _clientFactory = container.IsRegistered<ISmtpClientFactory>()
                ? container.Resolve<ISmtpClientFactory>()
                : new SmtpClientFactory();

            // get an apikey for accessing the services without it's private/internal keys
            _emailApikey = config["apikey"].AsText;
            result.Return();
        }
Exemplo n.º 5
0
        internal Yield ConfigureSmtp(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            var configuration = context.GetParam("configuration");
            var settingsDoc = request.ToDocument();
            _log.DebugFormat("configuring settings for configuration '{0}'", configuration);
            var host = settingsDoc["smtp-host"].AsText;
            var apikey = settingsDoc["apikey"].AsText;
            if(string.IsNullOrEmpty(host) && string.IsNullOrEmpty(apikey)) {
                response.Return(DreamMessage.BadRequest("must specify either new smtp config with a host or specify an apikey"));
                yield break;
            }
            SmtpSettings settings;
            if(string.IsNullOrEmpty(host)) {
                settings = new SmtpSettings() {
                    Host = _defaultSettings.Host,
                    Apikey = apikey,
                    AuthPassword = _defaultSettings.AuthPassword,
                    AuthUser = _defaultSettings.AuthUser,
                    EnableSsl = _defaultSettings.EnableSsl,
                    Port = _defaultSettings.Port,
                };
            } else {
                _log.DebugFormat("Smtp Host: {0}", host);
                settings = new SmtpSettings {
                    Host = host,
                    AuthUser = settingsDoc["smtp-auth-user"].AsText,
                    AuthPassword = settingsDoc["smtp-auth-password"].AsText,
                    Apikey = apikey,

                    // Note (arnec): ssl requires mono 2.0 and likely root certificate import via 'mozroots --import --ask-remove --machine'
                    EnableSsl = settingsDoc["use-ssl"].AsBool ?? false
                };
                if(settingsDoc["smtp-port"].AsInt.HasValue) {
                    settings.Port = settingsDoc["smtp-port"].AsInt.Value;
                }
            }
                lock(_smtpSettings) {
                    _smtpSettings[configuration] = settings;
                }
            response.Return(DreamMessage.Ok());
            yield break;
        }