Notification Service and Message Template

Posted by Community Admin on 04-Aug-2018 23:29

Notification Service and Message Template

All Replies

Posted by Community Admin on 14-Feb-2013 00:00

Hi there,

I'm trying to send out notifications to particular mailing lists. I have created a message template to be used as the content of the mailing list as follows:

var ns = SystemManager.GetNotificationService();

var MessageTemplate = NewslettersManager.GetManager().GetMessageBodies().Where(mB => mB.IsTemplate == true && mB.Name == "MyTemplateName").FirstOrDefault();

IMessageJobRequest job = new MessageJobRequestProxy()
                       
                            MessageTemplateId = MessageTemplate.Id,
                            Subscribers  = subscribers,
                            SenderProfileName = "profileName"
                        ;              
var messageJobId = ns.SendMessage(context, job, null);

An exception is currently being thrown on SendMessage. The exception is: You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user.

The template actually exists, I have confirmed. However, if I change the way I declare the job as follows (to not use a message template but instead create one inline, all works fine (i receive the notification).

IMessageTemplateRequest tmpl = new MessageTemplateRequestProxy()
                       
                            Subject = "Test",
                            BodyHtml = "HELLO"
                        ;

IMessageJobRequest job = new MessageJobRequestProxy()
                       
                            MessageTemplate = tmpl,
                            Subscribers  = subscribers,
                            SenderProfileName = profileName
                        ;

var messageJobId = ns.SendMessage(context, job, null);

Can anybody shed light on this issue? I would really prefer to be able provide MessageTemplateID (created in the UI) as opposed to manually creating the content (template) through code.

 Thanks!

Posted by Community Admin on 19-May-2014 00:00

Hi there,

I'm trying to work with Notification Services without success. I setup smtp settings under Setting>Advanced>System>SMTP and Setting>Advanced>Notifications. The code runs without errors. Records are inserted into the table [sf_notif_cmplt_msg_job] but no mail are sent.

Can someone help me?

 This is the code:

void SendReminder(string email, string firstName, string lastName, string reminderName, string surgeryName)
    var ns = SystemManager.GetNotificationService();
    var context = new ServiceContext("system", "NotificationService");
 
    var contextDictionary = new Dictionary<string, string>();
    contextDictionary.Add("VisitReminder.ReminderName", reminderName);
    contextDictionary.Add("VisitReminder.SurgeryName", surgeryName);
 
    List<ISubscriberRequest> subscribers = new List<ISubscriberRequest>();
 
    var subscriber1 = new SubscriberRequestProxy()
    
        Email = email,
        FirstName = firstName,
        LastName = lastName,
        ResolveKey = Guid.NewGuid().ToString() + "-" + email
    ;
    subscribers.Add(subscriber1);
 
    //Name of an existing profile
    var profileName = "Default";
 
    NewslettersManager manager = NewslettersManager.GetManager();
    var messageSubject = manager.GetMessageBodies().Where(m => m.Name.Equals("ReminderSubject") && m.IsTemplate).FirstOrDefault();
    var messageBody = manager.GetMessageBodies().Where(m => m.Name.Equals("ReminderBodyEmail") && m.IsTemplate).FirstOrDefault();
 
    if (messageSubject != null && messageBody != null)
    
        var subjectTemplate = messageSubject.BodyText;
        var bodyTemplate = messageBody.BodyText;
        var tmpl = new MessageTemplateRequestProxy() Subject = subjectTemplate, BodyHtml = bodyTemplate ;
        var job = new MessageJobRequestProxy()
        
            MessageTemplate = tmpl,
            Subscribers = subscribers,
            SenderProfileName = profileName
        ;
 
        var messageJobId = ns.SendMessage(context, job, contextDictionary);
    

This thread is closed