I am looking for recommendations on how to handle the ability to queue and send different types of emails using Azure WebJobs.
Before sending the email there needs to do some business logic to compose, populate and then send. So say that I have 10 different types of emails
2 examples of emails
1) when a booking is confirmed I would like to something like
var note = new BookingConfirmNotification() { BookingId = 2 }
SomeWayToQueue.Add(note)
2) or when I need reminder the user to do something
var reminder = new ReminderNotification() { UserId = 3 }
SomeWayToQueue.Add(reminder, TimeSpan.FromDays(1)
Is it better to create a queue for each of different types of emails with QueueTrigger on WebJob .. or is there a better way to do this?
Update
So I thought you might be able to add different Function/Methods with different strongly-typed classes to trigger different methods, but that doesnt seem to work.
public void SendAccountVerificationEmail(
[QueueTrigger(WebJobHelper.EmailProcessorQueueName)]
AccountVerificationEmailTask task, TextWriter log)
{
log.WriteLine("START: SendAccountVerificationEmail: " + task.UserId);
const string template = "AccountVerification.cshtml";
const string key = "account-verification";
PrepareAndSend(user.Email, "Account confirmation", template, key, task, typeof(AccountVerificationEmailTask));
log.WriteLine("END: SendAccountVerificationEmail: " + task.UserId);
}
public void SendForgottonPasswordEmail(
[QueueTrigger(WebJobHelper.EmailProcessorQueueName)]
ForgottonPasswordEmailTask task, TextWriter log)
{
const string template = "ForgottonPassword.cshtml";
const string key = "forgotton-password";
PrepareAndSend(user.Email, "Forgotton password", template, key, task, typeof(ForgottonPasswordEmailTask));
}
This doesn't work - different methods are fired randomly when a message is added to the queue
How can I implement something like this using WebJobs?