Manage incoming mail routing rules through the API #1483
Replies: 4 comments
-
Quickly added the following code. #/app/api/controllers/route_api_controller.rb
controller :route do
friendly_name "Route API"
description "This API allows you to manage route"
authenticator :server
action :add do
title "Add route"
description "This action allows you to send a add route for incoming mail"
# Acceptable Parameters
param :from, "The e-mail address for the From header", :type => String
param :to, "The e-mail address for the To header", :type => String
param :spam_mode, "Spam mode", :type => String
# Errors
error 'ValidationError', "The provided data was not sufficient to send an email", :attributes => {:errors => "A hash of error details"}
error 'NoRecipients', "There are no recipients defined to received this message"
error 'FromAddressMissing', "The From address is missing and is required"
error 'UnauthenticatedFromAddress', "The From address is not authorised to send mail from this server"
# Return
returns Hash
# Action
action do
user_name, domain_name = params.from.split("@")
endpoint = AddressEndpoint.find_or_create_by(server: identity.server, address: params.to)
domain = Domain.find_by_name(domain_name)
route = Route.create(server: identity.server, endpoint: endpoint, name: user_name, domain: domain, spam_mode: params.spam_mode, mode: 'Endpoint')
if route.valid?
result = { data: route }
else
error route.errors.first
end
end
end
end |
Beta Was this translation helpful? Give feedback.
-
Unfortunately there isn't a configuration API right now, all changes need to be done in the UI. Obviously you can add more code to do so but be wary of future updates as your code may be removed by that process. |
Beta Was this translation helpful? Give feedback.
-
Will thank you! I'll try to arrange the code as a module. |
Beta Was this translation helpful? Give feedback.
-
Credit to atech, they certainly make mean software. A PR with this in would be a great starting point for future expansion and discussion. |
Beta Was this translation helpful? Give feedback.
-
Hello!
Is it possible to create routing rules for incoming mail through an API?
As far as I understand the API functionality now, is it limited to sending messages only?
If there is no such possibility now through the standard API, what is the best way to add such functionality to Postal?
The functionality is very necessary, is it possible to write a gem to extend the functionality? What are the recommendations?
Beta Was this translation helpful? Give feedback.
All reactions