Base solution for your next web application
Open Closed

How to override default SMTP host setting ? #430


User avatar
0
klainer created

Hello,

I need to override default SMTP server setting configuration. I created this class:

public class MySettingProvider : SettingProvider
    {
        public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
        {
            return new[]
                    {
                    new SettingDefinition(
                        "SmtpServerAddress",
                        "192.168.50.14"
                        )
                };
        }
    }

And in Web.Module I´m calling this:

public override void PreInitialize()
 {
            Configuration.Settings.Providers.Add<MySettingProvider>();
}

But this no work! What is correct appropoach to do it ? Thnaks !


5 Answer(s)
  • User Avatar
    0
    gvb created

    Here is my code for the overriding of the settings

    I use those using statement :

    using Abp.Configuration; using Abp.Net.Mail;

    Setting Provider :

    public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
            {
                return new[]
                    {
                         new SettingDefinition(
                            EmailSettingNames.Smtp.Host,
                            string.Empty
                            ),
                        new SettingDefinition(
                            EmailSettingNames.Smtp.Port,
                            string.Empty
                            ),
                        new SettingDefinition(
                            EmailSettingNames.Smtp.UserName,
                            string.Empty
                            ),
                        new SettingDefinition(
                            EmailSettingNames.Smtp.Password,
                            string.Empty
                            ),
                        new SettingDefinition(
                            EmailSettingNames.Smtp.EnableSsl,
                            string.Empty
                            ),
                        new SettingDefinition(
                            EmailSettingNames.Smtp.UseDefaultCredentials,
                            string.Empty
                            )
                    };
            }
    

    Seeder

    if (!_context.Settings.Any())
                {
                    _context.Settings.Add(new Abp.Configuration.Setting
                    {
                        Name = EmailSettingNames.Smtp.Host,
                        Value = "smtp.gmail.com"
                    });
    
                    _context.Settings.Add(new Abp.Configuration.Setting
                    {
                        Name = EmailSettingNames.Smtp.Port,
                        Value = "587"
                    });
    
                    _context.Settings.Add(new Abp.Configuration.Setting
                    {
                        Name = EmailSettingNames.Smtp.UserName,
                        Value = EMAILVALUE
                    });
    
                    _context.Settings.Add(new Abp.Configuration.Setting
                    {
                        Name = EmailSettingNames.Smtp.Password,
                        Value = PASSWORD VALUE
                    });
    
                    _context.Settings.Add(new Abp.Configuration.Setting
                    {
                        Name = EmailSettingNames.Smtp.EnableSsl,
                        Value = "true"
                    });
    
                    _context.Settings.Add(new Abp.Configuration.Setting
                    {
                        Name = EmailSettingNames.Smtp.UseDefaultCredentials,
                        Value = "false"
                    });
                }
    
  • User Avatar
    0
    klainer created

    Works, thanks !!

  • User Avatar
    0
    gouse created

    I have tried the same. Still not working for me. Can u pls help me?

  • User Avatar
    0
    gouse created

    Can u pls show me code sample and place of code change(core, application, etc)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi GOUSE,

    Your case might be different. Do you have any data in database ? Can you share your Seed method of your DbContext and related classes ?

    Thanks.