Closed pkejval closed 1 year ago
Try
replace_rcpt sql_query {
import pg_con
lookup "SELECT address AS addresses FROM aliases WHERE alias = $1"
}
It is not necessary to use STRING_AGG
, sql_query
already handles multiple rows in query result as multiple values.
Yes, its working, thank you! Reason for opening this request was this sentence in documentation:
https://maddy.email/reference/table/sql_query/
lookup query
Required.
SQL query to use to obtain the lookup result.
It will get one named argument containing the lookup key. Use :key placeholder to access it in SQL.
The result row set should contain one row, one column with the string that will be used as a lookup result.
If there are more rows, they will be ignored. If there are more columns, lookup will fail.
If there are no rows, lookup returns "no results". If there are any error - lookup will fail.
hence I must admit I didn't try it without STRING_AGG() 😵💫
Sorry for bothering you with nonexistent issue!
Woops, that's outdated and should be fixed.
Use case
What problem you are trying to solve?
_replacercpt file /etc/maddy/aliases file can have multiple aliases for one address like it's said in docs:
I'd like to have table for this mapping in database and query for them like this:
Actually maddy returns this message when multiple addreses are set for alias:
smtp: MAIL FROM error (deferred) {"msg_id":"","rcpt":"alias@domain.tld","reason":"Unable to normalize the sender address","smtp_code":553,"smtp_enchcode":"5.1.7","smtp_msg":"Unable to normalize the sender address"}
Your idea for a solution
Parse SQL column like you're parsing text file. Allow multiple comma-separated values.