Email sender profiles

The profiles in the Notification service contain the specific configuration for the sending channel. Each profile must have a name and a type that is/are defined by the ISenderProfileinterface. In the case of SMTP profile type, each profile contains the settings for the SMTP server.

SmtpSenderProfileProxyimplements ISenderProfileinterface and can be used as a parameter, where the interface is specified.

Create a new SMTP sender profile that you can use later during the messaging

One way to create a sender profile is to use the API and create it from code. You can do this using the following code sample:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Notifications;
using Telerik.Sitefinity.Services.Notifications.Configuration;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
    public partial class NotificationServiceSnippets
    {
        public static void CreateSenderProfile()
        {
            var ns = SystemManager.GetNotificationService();
            var context = new ServiceContext("myNotificationAccount", "MyCustomModule");
            var senderProfileName = "DefaultSmtpProfile";

            var senderProfile = new SmtpSenderProfileProxy()
            {
                ProfileName = senderProfileName,
                DefaultSenderEmailAddress = "no.reply@telerik.com",
                Host = "testsmtpserver.telerik.com",
                Port = 25,
                UseSSL = false
            };
            ns.SaveSenderProfile(context, senderProfile);
        }
    }
}

Another way to create a sender profile is to register the new profile directly in the configuration file, using the following code:

XML
<notificationsConfig xmlns:config="urn:telerik:sitefinity:configuration" xmlns:type="urn:telerik:sitefinity:configuration:type" config:version="5.0.4461.36629">
  <profiles>
    <add defaultSenderEmailAddress="no-reply@test.com" host="testsmtp01.telerik.com" port="25" useAuthentication="False" useSSL="False" profileName="DefaultSmtpProfile" type:this="Telerik.Sitefinity.Services.Notifications.Configuration.SmtpSenderProfileElement, Telerik.Sitefinity.Services.Notifications.Impl" />
  </profiles>
</notificationsConfig>

Specify the profile used when creating a message job

The following sample demonstrates how to specify the default smtp profile when creating a message job:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Services.Notifications;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
    public partial class NotificationServiceSnippets
    {
        public static void SpecifyProfileWhenCreatingMessageJob()
        {
            //Id of an existing subscription list
            Guid subscriptionListId = Guid.Empty;
            //Id of an existing message template
            Guid templateId = Guid.Empty;
            //Name of an existing profile
            var senderProfileName = "DefaultSmtpProfile"; 

            var job = new MessageJobRequestProxy()
            {
                MessageTemplateId = templateId,
                SubscriptionsListId = subscriptionListId,
                SenderProfileName = senderProfileName
            };
        }
    }
}

```    For more information, see [For developers: Email message jobs](slug://for-developers-email-message-jobs).    
## Get a sender profile using the NotificationService API.
 The example below will show you how to get the default sender profile:

```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Notifications;
using Telerik.Sitefinity.Services.Notifications.Configuration;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
    public partial class NotificationServiceSnippets
    {
        public static void GettingSenderProfileViaNotificationServiceAPI()
        {
            var senderProfileName = "DefaultSmtpProfile";
            var context = new ServiceContext("myNotificationAccount", "MyCustomModule");
            INotificationService ns = SystemManager.GetNotificationService();
            ISenderProfile profile = ns.GetSenderProfile(context, senderProfileName);
        }
    }
}

Get a collection of all profiles using the NotificationService API

The example below will show you how to get a collection of all profiles:

C#
using System.Collections.Generic;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Notifications;
using Telerik.Sitefinity.Services.Notifications.Configuration;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DeepDive.NotificationService
{
    public partial class NotificationServiceSnippets
    {
        public static void GetAllSenderProfiles()
        {
            INotificationService ns = SystemManager.GetNotificationService();
            var parameters = new QueryParameters()
            {
                Skip = 2,
                Take = 1
            };

            IEnumerable<ISenderProfile> profiles = ns.GetSenderProfiles(parameters);
        }
    }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.