4

we just moved some of our workloads to azure for which i am currently managing, i read a little about service bus and was wondering if i can use it to queue emails

applications hosted in azure though the use of a custom library will deliver their emails to a service bus queue where one or more worker processes will pick messages off the queue and send then though a mail relay service.

this will free my developers from the details of which mail relay service i am using at anytime and i can also perform further processing of the messages before sending without the developers changing their code.

my questions are, is this possible, if it is, is it advisable and is there anything i need to watch out for when implementing such a solution. any pointers on how to do it will also be appreciated

juvchan
  • 6,113
  • 2
  • 22
  • 35
araoko
  • 93
  • 2
  • 6
  • Yes it is possible, what have you tried till now? It is just a queuing system to handle workloads. – Peter Mar 15 '16 at 10:48
  • i have not given it a try, just getting used to azure infrastructure, i just want to know if its worth the effort involved or its a dead end. i also want to know if its a good idea – araoko Mar 15 '16 at 12:03

3 Answers3

7

Yes, it is a reasonable solution to add messages to an Azure Service Bus Queue that are later retrieved by an application that goes and send emails based on the details in the queued messages. This is a good way to decouple your various applications using a Microservices approach to providing an email sending service to be used either within the different pieces of a single app, or even across many apps within the organization.

One thing to watch out for is that the Message size in the Azure Service Bus Queue does have a maximum size limit. Depending on the length of the content being sent in the emails, you will need to store the details of the message somewhere, perhaps a database or Azure Table Storage. Then the message in the Queue would contain an identifier, such as a GUID, that could be used to look up the message details later when the receiving application processes it to send the email out. No matter the size of the massage in the queue, emails can get quite long, so using this approach is probably the best option for you so you wont have issues later with the implementation.

Chris Pietschmann
  • 29,502
  • 35
  • 121
  • 166
  • Do you know an efficient way to serialize a MailMessage Object? I want a situation where the users of this library will create the mail message like they normally do but send through the library, all the implementations I have seen so far involves either using an internal method of a .net class with can change at anytime of serializing the object to disk first and then reading it which can affect performance. – araoko May 03 '16 at 07:05
  • @araoko Serializing MailMessage isn't something I've ever tried. I wouldn't recommend this. Email messages can be fairly long and easily use up much more than the available message size for a Service Bus Queue message. I would recommend that you create your own class similar to MailMessage, then store that in Table Storage with a pointer in the Queue Message. – Chris Pietschmann May 03 '16 at 13:21
  • I want to serialize the MailMessage to blob storage as you recommended and pass a pointer to it on the queue. if i create my own class, it means all existing codes will be changed to use my class, i will prefer that as a last resort. – araoko May 03 '16 at 15:17
1

Without knowing anything about your system, requirements, on need in messaging vs queuing, I'm going to say that following.

  • If your application has a need in messaging, then go ahead and use Azure Service Bus for queuing emails as well.
  • In case the answer is "no", use something that is solely queuing: Azure Storage Queues.
Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
0

It's possible and it's good choice. Most of email services uses queue in their systems.

You can use priority property of queue. Transactional Mails>Notification Mails>Marketing Mails, you can give high to low priority. Because queue works fifo and transactional mails shouldn't wait for marketing mails.

You can use Labels distinguish messages, before implemantation.

If you can't send an email after for some tries(default 10 for Azure). You should move it to dead queue azure service bus does this for you. But then you should consume deadqueue for handling this emails.

Erkan Demirel
  • 4,302
  • 1
  • 25
  • 43