Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the hostname (FQDN) configurable #74

Merged
merged 1 commit into from Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,7 @@ The package can be installed as:
config :my_app, MyApp.Mailer,
adapter: Bamboo.SMTPAdapter,
server: "smtp.domain",
hostname: "your.domain",
port: 1025,
username: "your.name@your.domain", # or {:system, "SMTP_USERNAME"}
password: "pa55word", # or {:system, "SMTP_PASSWORD"}
Expand All @@ -45,6 +46,8 @@ The package can be installed as:
*Sensitive credentials should not be committed to source control and are best kept in environment variables.
Using `{:system, "ENV_NAME"}` configuration is read from the named environment variable at runtime.*

The *hostname* option sets the FQDN to the header of your emails, its optional, but if you don't set it, the underlying `gen_smtp` module will use the hostname of your machine, like `localhost`.

4. Follow Bamboo [Getting Started Guide](https://github.com/thoughtbot/bamboo#getting-started)

## Usage
Expand Down
4 changes: 4 additions & 0 deletions lib/bamboo/adapters/smtp_adapter.ex
Expand Up @@ -14,6 +14,7 @@ defmodule Bamboo.SMTPAdapter do
config :my_app, MyApp.Mailer,
adapter: Bamboo.SMTPAdapter,
server: "smtp.domain",
hostname: "www.mydomain.com",
port: 1025,
username: "your.name@your.domain", # or {:system, "SMTP_USERNAME"}
password: "pa55word", # or {:system, "SMTP_PASSWORD"}
Expand Down Expand Up @@ -343,6 +344,9 @@ defmodule Bamboo.SMTPAdapter do
defp to_gen_smtp_server_config({:retries, value}, config) when is_integer(value) do
[{:retries, value} | config]
end
defp to_gen_smtp_server_config({:hostname, value}, config) when is_binary(value) do
[{:hostname, value} | config]
end
defp to_gen_smtp_server_config({conf, {:system, var}}, config) do
to_gen_smtp_server_config({conf, System.get_env(var)}, config)
end
Expand Down
2 changes: 2 additions & 0 deletions test/lib/bamboo/adapters/smtp_adapter_test.exs
Expand Up @@ -62,6 +62,7 @@ defmodule Bamboo.SMTPAdapterTest do
adapter: SMTPAdapter,
server: "smtp.domain",
port: 1025,
hostname: "your.domain",
username: "your.name@your.domain",
password: "pa55word",
transport: FakeGenSMTP
Expand Down Expand Up @@ -449,6 +450,7 @@ defmodule Bamboo.SMTPAdapterTest do
defp assert_configuration(bamboo_config, gen_smtp_config) do
assert bamboo_config[:server] == gen_smtp_config[:relay]
assert bamboo_config[:port] == gen_smtp_config[:port]
assert bamboo_config[:hostname] == gen_smtp_config[:hostname]
assert bamboo_config[:username] == gen_smtp_config[:username]
assert bamboo_config[:password] == gen_smtp_config[:password]
assert bamboo_config[:tls] == gen_smtp_config[:tls]
Expand Down