64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/mta_settings.rb', line 64
def self.from_env(env = ENV)
domain = env['MTA_DOMAIN'] || LOCALHOST
if url = env[env['MTA_PROVIDER'].presence || 'MTA_URL'].presence
method, settings = from_url(url)
if method == :smtp && settings[:domain] == LOCALHOST
settings[:domain] = domain
end
[method, settings]
elsif env['SENDGRID_USERNAME'].present?
[:smtp, {
:address => "smtp.sendgrid.net",
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true,
:user_name => env['SENDGRID_USERNAME'],
:password => env['SENDGRID_PASSWORD'],
:domain => domain,
}]
elsif env['MANDRILL_APIKEY'].present?
[:smtp, {
:address => "smtp.mandrillapp.com",
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true,
:user_name => env['MANDRILL_USERNAME'],
:password => env['MANDRILL_APIKEY'],
:domain => domain,
}]
elsif env['POSTMARK_API_TOKEN'].present?
[:smtp, {
:address => env['POSTMARK_SMTP_SERVER'] || 'smtp.postmarkapp.com',
:port => 25,
:authentication => :cram_md5,
:enable_starttls_auto => true,
:user_name => env['POSTMARK_API_TOKEN'],
:password => env['POSTMARK_API_TOKEN'],
:domain => domain,
}]
elsif env['MAILGUN_SMTP_LOGIN'].present?
[:smtp, {
:address => env['MAILGUN_SMTP_SERVER'] || 'smtp.mailgun.org',
:port => env['MAILGUN_SMTP_PORT'] || '25',
:authentication => :plain,
:enable_starttls_auto => true,
:user_name => env['MAILGUN_SMTP_LOGIN'],
:password => env['MAILGUN_SMTP_PASSWORD'],
:domain => domain,
}]
elsif env['MAILTRAP_API_TOKEN'].present?
response = Net::HTTP.get(URI.parse("https://mailtrap.io/api/v1/inboxes.json?api_token=#{env['MAILTRAP_API_TOKEN']}"))
first_inbox = JSON.parse(response)[0]
[:smtp, {
:address => first_inbox['domain'],
:port => first_inbox['smtp_ports'][0],
:authentication => :plain,
:user_name => first_inbox['username'],
:password => first_inbox['password'],
:domain => first_inbox['domain']
}]
end
end
|