
假設我希望人們向我的伺服器發送電子郵件,並且我想將它們全部轉發到不同的電子郵件地址。例如,我有以下映射:
[email protected] => [email protected]
[email protected] => [email protected]
[email protected] => [email protected]
...
[email protected] => [email protected]
這個清單可能會變得很大,我希望能夠輕鬆地將它們全部轉發。我還想讓用戶輕鬆配置,以便他們可以為自己設定映射(就像如何輕鬆地在 gmail 上設定轉發等)
我目前的伺服器上有 postfix,但似乎使用 postfix 我必須編輯設定檔並一直重新加載,當我想到一個巨大的列表時,它聽起來不具有可擴展性。
實現這一目標的最佳方法是什麼?我不一定要使用 postfix,如果需要的話可以用完全不同的系統來滿足這個目的。
答案1
Postfix 支援很多查找表您可以使用資料庫查找表(mysql,pgsql or sqlite
)來儲存如此大的列表,並且在使用它們時無需重新載入 postfix。假設forwards
您的 postgres 資料庫中有一個包含列emailaddress
和 的表forwards
。
emailaddress forwards
[email protected] [email protected]
[email protected] [email protected]
[email protected] [email protected]
你可以配置你的後綴來使用它。
#/etc/postfix/main.cf
#... other main.cf contents omitted
virtual_alias_domains = myserver.net
virtual_alias_maps = pgsql:/etc/postfix/pgsql_forwards.cf
#...
的內容/etc/postfix/pgsql_forwards.cf
應該是這樣的
#/etc/postfix/pgsql_forwards.cf
dbname = emaildb
hosts = db.example.net
user = emailuser
password = somerandompass
query = SELECT forwards FROM forwards where emailaddress='%s';
- 但首先要確保所有查找表都是透過執行您的後綴來編譯的
postconf -m
。我看過很多人使用mysql
. - 為了讓你的用戶能夠自己設定轉發,你必須給他們一些 web 應用程式來更新 postfix 使用的資料庫表。
希望有幫助。