Base solution for your next web application
Open Closed

Sending email when a user gets a notification #1356


User avatar
0
joe704la created

I added a couple methods to the AppNotifier class. I want to be able to send emails when a user gets a notification, that they received a specific notification. Would you have any good ideas how I can do this for the ones where people are only registered to receive the notification?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Inject INotificationStore into your AppNotifier. Then you can use

    _notificationStore.IsSubscribedAsync
    

    method to check if a user is subscribed to a specific notification.

    This interface has some other methods you might find useful for your case.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    joe704la created

    Okay, so I am guessing in the AppNotifier I would just query the users table in the notification method and then check if each user is subscribed to this notification and then send them the email?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    hikalkan created
    Support Team

    Actually, this would not be performant.

    Use INotificationSubscriptionManager.GetSubscriptionsAsync (<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Notifications/INotificationSubscriptionManager.cs#L49">https://github.com/aspnetboilerplate/as ... ger.cs#L49</a>) to get subscribed users and send them emails.

    As an alternative, you can inherit from NotificationStore and override InsertUserNotificationAsync method (<a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/dev/src/Abp.Zero/Notifications/NotificationStore.cs#L85">https://github.com/aspnetboilerplate/mo ... ore.cs#L85</a>). In that override, call base then send your email. Note that you should replace INotificationStore with YourNotificationStore (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Startup-Configuration#replacing-built-in-services">http://www.aspnetboilerplate.com/Pages/ ... n-services</a>)

    Have a nice day.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)