Hello everyone, I can’t make my phoenix application send emails using postfix installed on the same VPS.
The result of command
postconf -n
looks like this:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
compatibility_level = 2
inet_interfaces = loopback-only
inet_protocols = all
mailbox_size_limit = 0
milter_default_action = accept
milter_protocol = 6
mydestination =
myhostname = mytestdomain.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
non_smtpd_milters = $smtpd_milters
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_milters = local:/opendkim/opendkim.sock
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
virtual_alias_maps = hash:/etc/postfix/virtual
When I give the command to send email in the console like this:
echo "This is the body of the email" | mail -s "This is the subject" mymailaddress@gmail.com
I get the email in my mailbox, everything works as expected, I also see the postfix work by looking into it’s log:
sudo tail -f /var/log/mail.log
May 28 16:14:31 mytestdomain postfix/pickup[28788]: 6E8445DC28: uid=1000 from=<testuser@mytestdomain.com>
May 28 16:14:31 mytestdomain postfix/cleanup[30829]: 6E8445DC28: message-id=<20190528161431.6E8445DC28@mytestdomain.eu>
May 28 16:14:31 mytestdomain postfix/qmgr[6445]: 6E8445DC28: from=<testuser@mytestdomain.com>, size=399, nrcpt=1 (queue active)
May 28 16:14:31 mytestdomain postfix/smtp[30831]: connect to gmail-smtp-in.l.google.com[2a00:1450:400c:c00::1a]:25: Network is unreachable
May 28 16:14:31 mytestdomain postfix/smtp[30831]: 6E8445DC28: to=<testuser@gmail.com>, relay=gmail-smtp-in.l.google.com[64.233.184.24]:25, delay=0.43, delays=0.02/0.01/0.17/0.24, dsn=2.0.0, status=sent (250 2.0.0 OK 1559060071 n7si2302256wmc.53 - gsmtp)
May 28 16:14:31 mytestdomain postfix/qmgr[6445]: 6E8445DC28: removed
But emails from my phoenix application are not sent, there is nothing in the postfix log and nothing in my mailbox. My config looks like this:
# Configures the mailer
config :jp, JpWeb.Mailer,
adapter: Swoosh.Adapters.SMTP,
relay: "mytestdomain.com",
ssl: false,
tls: :always,
port: 1025,
retries: 2,
no_mx_lookup: false
I tried with ssl: true first but then I found the topic on this forum where it was recommended to set it to false, so I did it but it didn’t help. Also I tried to set port to 25 but with no result.
The email is sent like this:
JpWeb.SpecialistRequestEmail.specialist_request_email(id, url, email, phone, name) |> JpWeb.Mailer.deliver
and the function specialist_request_email looks like this:
defmodule JpWeb.SpecialistRequestEmail do
import Swoosh.Email
def specialist_request_email(specialist_id, url, email, phone, name) do
new()
|> to({"MyTestDomain administrator", "testuser@gmail.com"})
|> from({"Notifications system", "notifications@mytestdomain.com"})
|> subject("New specialist request")
|> html_body("<h1>Specialist request details</h1><div>Name: #{name}</div><div>Phone: #{phone}</div><div>E-mail: #{email}</div><div><a href=\"#{url}\">Specialist ##{specialist_id}#</a></div>")
|> text_body("Specialist request details\nName: #{name}, Phone: #{phone}, E-mail: #{email}, Specialist Id: #{specialist_id}, Link: #{url}")
end
end
In my mix.exs file I added dependencies:
{:swoosh, "~> 0.23"},
{:gen_smtp, "~> 0.13"},
And added them to extra_applications (should I?):
def application do
[
mod: {Jp.Application, []},
extra_applications: [:swoosh, :gen_smtp]
]
end
What do I miss?