Send Email with C# in Telligent Community 6.0

Send Email with C# in Telligent Community 6.0

This question is answered

Hello,

I had a module in 5.5 that was adding a mail to the queue. The same code against the 6.0 SDK doesn't work. What's the equivalent in v6.0 for the following code?

MailRoom.Components.Emails.QueueMessage(mail);

Thanks

Verified Answer
  • What I've found to be slightly equivalent is :

    var emailContextService = ServiceLocator.Get<IEmailContextService>();
    var emailTemplateUtility = ServiceLocator.Get<IEmailTemplateUtility>();
    var emailQueuingService = ServiceLocator.Get<IEmailQueuingService>();
    var emailTemplateService = ServiceLocator.Get<IEmailTemplateService>();

    var emailContext = emailContextService.Create(new[] { user }, emailTemplateUtility.FormatFromSite(), user.EnableHtmlEmail ?? false, user.Language, viewModel);

    emailQueuingService.Queue(emailContext, emailTemplateService.Get(template,user.Language));

    Where

    • viewModel is an object containing data required by the template
    • template the name of the email template I wish to send
    It isn't brilliant, and in my case  it's abstracted away from most code that just wishes to send an email.
    Hope it helps
All Replies
  • What I've found to be slightly equivalent is :

    var emailContextService = ServiceLocator.Get<IEmailContextService>();
    var emailTemplateUtility = ServiceLocator.Get<IEmailTemplateUtility>();
    var emailQueuingService = ServiceLocator.Get<IEmailQueuingService>();
    var emailTemplateService = ServiceLocator.Get<IEmailTemplateService>();

    var emailContext = emailContextService.Create(new[] { user }, emailTemplateUtility.FormatFromSite(), user.EnableHtmlEmail ?? false, user.Language, viewModel);

    emailQueuingService.Queue(emailContext, emailTemplateService.Get(template,user.Language));

    Where

    • viewModel is an object containing data required by the template
    • template the name of the email template I wish to send
    It isn't brilliant, and in my case  it's abstracted away from most code that just wishes to send an email.
    Hope it helps
  • Thanks for your response.

    What about that?

    Telligent.Evolution.MailGateway.MailRoom.EmailHandler.Process(mail);

  • I think that's related to bulk emails for forums and wikis which are handled differently, and I was supposing you wanted to "just" send an email.

  • Yes, what I want is just to send an 'EmailMessage'.

    I suppose your code is the right way.

    Thanks again!

  • I'm not positive it's the right way, but it works for us and I hope it works for you.

    Just be prepared to change it a bit in case there's a better way.