getting smtp settings

Posted by Community Admin on 04-Aug-2018 15:02

getting smtp settings

All Replies

Posted by Community Admin on 01-Mar-2013 00:00

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?

Posted by Community Admin on 01-Mar-2013 00:00

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

Posted by Community Admin on 01-Mar-2013 00:00

That worked. Thanks so much Daniel!

Posted by Community Admin on 17-Mar-2013 00:00

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

Posted by Community Admin on 04-Oct-2013 00:00

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. :) 

Posted by Community Admin on 07-Oct-2013 00:00

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

Posted by Community Admin on 27-Sep-2017 00:00

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? 

This thread is closed