gotthardp/rabbitmq-email

Is it possible to route emiails based on subject?

gbhat618 opened this issue · 1 comments

Currently I have implemented it,
by putting all the emails into a single queue, two consumer threads will be fetching emails from this queue and based on the subject, emails are pushed to separate queue.

If there is a way to separate emails based on subjects, that will be great.

I think what I am looking for is routing emails, based on the attributes in email-headers
https://github.com/gotthardp/rabbitmq-email#smtp-headers-extraction

Yes, you can do this.

When the rabbitmq_email plugin starts, it creates a topic exchange for incoming email. The name of the exchange is controlled by the email_domains setting (docs).

However, you can delete this exchange and create a new headers exchange with the same name. Be sure to create a durable exchange that will survive restarts.

Then, when you bind your queues to the exchange, you would bind them with arguments to match on the Subject header. Here is the output of rabbitmqctl list_bindings from my test:

source_name  source_kind destination_name  destination_kind  routing_key  arguments
email-in     exchange    subject-1-msgs    queue                          [{"Subject","subject-1"}]
email-in     exchange    subject-2-msgs    queue                          [{"Subject","subject-2"}]

Note that the Subject must exactly match. There is no way to specify regular expressions. You can also add the "x-match", "any" argument and have multiple values for Subject if you need to match more than one subject for a particular queue.