We are using Rails 7 to build an application which, amongst other features, should perform some actions when e-mails are sent to one of its e-mail addresses (which have, for instance, the format ticket-{uuid}@ourdomain.com
).
Rails' ActionMailbox's routing works fine for direct e-mails. However, when e-mails are forwarded, they are not recognized by ActionMailbox at all.
How can we ensure that forwarded e-mails are also handled and routed correctly with ActionMailbox?
EDIT: A simplified version of the code we are using:
class ApplicationMailbox < ActionMailbox::Base
routing /^ticket-(. )@ourdomain.com$/i => :service_tickets
end
class ServiceTicketsMailbox < ApplicationMailbox
def process
puts "processing email: #{mail.inspect}"
# ... and then we extract its fields
# and store some of them in the database.
end
end
CodePudding user response:
The API never includes functionality to see any other mail-address than the latest one in the delivery stack. The only option the API offers by itself is to use InboundEmail::source to get the raw message for further parsing.
After this process I could imagine to use RoutingJob to forward the mail to the correct receiver.
I'm not sure if Callbacks could help.
Also concerning MessageId I don't know if it's possible to extract the correct Ids.
As far as I see the whole challenge requires at least some work and I see there no simple solution.
CodePudding user response:
Ok I think I found the issue:
When you send a normal e-mail the To header looks like this To: ticket-123@@ourdomain.com
and this matches with /^ticket-(. )@ourdomain.com$/i
However when you forward the e-mail the header looks like this To: John Doe <[email protected]>
and this will not match with your regex.
Change the regex to /ticket-(. )@ourdomain.com/i
and it should work.
You can try it out on https://regexr.com/