getting smtp settings - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

getting smtp settings

  • getting smtp settings
  • Hi,

    Before 5.0, I used to get my stmp settings using the following code:

                    var manager = ConfigManager.GetManager();
                    string smtpHost = manager.GetSection<NewslettersConfig>().SmtpHost;
                    int smtpPort = manager.GetSection<NewslettersConfig>().SmtpPort;
                    var smtpClient = new SmtpClient(smtpHost, smtpPort);

    It still works, but I want to pull from the default profile for the notifications config instead. Can you please tell me how to do that?

  • Hi Amanda,

    To use the default profile from the Notification service, you could use e.g. this code:

    var senderProfileName = "Default";
    var context = new ServiceContext("myNotificationAccount", "MyCustomModule");
    INotificationService ns = SystemManager.GetNotificationService();
    ISenderProfile profile = ns.GetSenderProfile(context, senderProfileName);
    if (profile.ProfileType == "smtp")
       // Read the properties out of the CustomProperties property
       // [0]: [useSSL, False]
       // [1]: [defaultSenderEmailAddress, ]
       // [2]: [password, ]
       // [3]: [username, ]
       // [4]: [host, ]
       // [5]: [port, 25]
       // Devil: [useAuthentication, False]

    Not sure if that is the best way of doing this, but for me that worked.

    Kind regards,

  • That worked. Thanks so much Daniel!

  • Requires:
    Imports Telerik.Sitefinity.Configuration.Config
    Imports Telerik.Sitefinity.Configuration
    Imports Telerik.Sitefinity.Services.Notifications.Configuration

    Dim manager As ConfigManager = ConfigManager.GetManager()
    Dim section As NotificationsConfig = manager.GetSection(Of NotificationsConfig)()
    Dim myProfile As SmtpSenderProfileElement = section.Profiles("Default")

    Dim myhost As String = myProfile.Host.ToString
  • I was searching for a reference earlier and this thread shows up first on google, here is a clean way of getting the system's smtp settings: 

    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Services;

    var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;

    This is in no way related to the Notification system's profiles, however someone that stumbles on this thread may find it useful. :) 
  • Hi,

    Thank you for sharing this information with the community.

    Stefani Tacheva
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi Daniel, 

    I know this is an old post but I'm realising for the first time that Settings > System > SMTP is for pre SF 5x related features where as notification services is for post so I need to figure out how to use it correctly.

    What's the purpose of "myNotificationAccount" and "MyCustomModule" parameters in ServiceContext? I'm seeing those same values in Sitefinity's documentation as well, but there's no explanation as to what they're for. 

    This service also seems related to a subscriber list so from a developers standpoint is this not overkill in terms of just wanting to send some error details through to someone?