+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / getting smtp settings

getting smtp settings

6 posts, 0 answered
  1. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    01 Mar 2013
    Link to this post

    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?

  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    01 Mar 2013 in reply to Amanda Shafer
    Link to this post

    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]}
       // [6]: {[useAuthentication, False]}
    }

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

    Kind regards,
    Daniel

  3. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    01 Mar 2013 in reply to Daniel Plomp
    Link to this post

    That worked. Thanks so much Daniel!

  4. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    17 Mar 2013 in reply to Amanda Shafer
    Link to this post
    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
  5. Martin Scheer
    Martin Scheer avatar
    1 posts
    Registered:
    19 Mar 2012
    04 Oct 2013
    Link to this post

    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: 

    Usings:
    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. :) 
  6. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    07 Oct 2013
    Link to this post
    Hi,

    Thank you for sharing this information with the community.

    Regards,
    Stefani Tacheva
    Telerik
    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
6 posts, 0 answered