Skip to content

Commit

Permalink
support for smtp relay hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Apr 28, 2017
1 parent 695bdf9 commit 1adedc6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config/postal.defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ smtp_server:
ports:
- 2525

smtp_relays:
-
hostname:
port: 25
ssl_mode: Auto

dns:
mx_records:
- mx.postal.example.com
Expand Down
21 changes: 20 additions & 1 deletion lib/postal/smtp_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def start
hostname = server.hostname
port = server.port || 25
ssl_mode = server.ssl_mode
elsif server.is_a?(Hash)
hostname = server[:hostname]
port = server[:port] || 25
ssl_mode = server[:ssl_mode] || 'Auto'
else
hostname = server
port = 25
Expand Down Expand Up @@ -193,7 +197,7 @@ def finish
private

def servers
@options[:servers] || @servers ||= begin
@options[:servers] || self.class.relay_hosts || @servers ||= begin
mx_servers = []
Resolv::DNS.open do |dns|
dns.timeouts = [10,5]
Expand Down Expand Up @@ -248,5 +252,20 @@ def self.default_helo_hostname
Postal.config.dns.helo_hostname || Postal.config.dns.smtp_server_hostname || "localhost"
end

def self.relay_hosts
hosts = Postal.config.smtp_relays.map do |relay|
if relay['hostname'].present?
{
:hostname => relay['hostname'],
:port => relay['port'],
:ssl_mode => relay['ssl_mode']
}
else
nil
end
end.compact
hosts.empty? ? nil : hosts
end

end
end

0 comments on commit 1adedc6

Please sign in to comment.