0

I am trying to write an Elixir code which sends an email using the Swoosh library. For some reason, I keep getting the following error:-

{:error, 
 {:retries_exceeded, {:network_failure, 'smtp.gmail.com', {:error, :timeout}}}}

This is what my terminal looks like:-

C:\Users\USER\Desktop\mailapp>iex -S mix
Compiling 2 files (.ex)
Generated mailapp app
Interactive Elixir (1.5.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mailapp.UserEmail.welcome(%{name: "Name", email: "example.name@gmail.com"}) |> Mailapp.Mailer.deliver

My config\config.exs file looks like this:-

config :mailapp, Mailapp.Mailer,
  adapter: Swoosh.Adapters.SMTP, 
  adapter: Swoosh.Adapters.Test,
  adapter: Swoosh.Adapters.Local,
  relay: "smtp.gmail.com",
  username: "firstname.lastname",
  password: "password",
  tls: :always,
  auth: :always,
  port: 1025

My lib\mailapp.ex file looks like this:-

defmodule Mailapp.Mailer do
  use Swoosh.Mailer, otp_app: :mailapp
end

defmodule Mailapp.UserEmail do
  import Swoosh.Email

  def welcome(user) do
    new()
    |> to({user.name, user.email})
    |> from({"Name Name", "firstname.lastname@gmail.com"})
    |> subject("Hello")
    |> html_body("<h1>Hello #{user.name}</h1>")
    |> text_body("Hello #{user.name}\n")
  end
end

My test\mailapp_test.exs file looks like this:-

defmodule Mailapp.UserTest do
  use ExUnit.Case, async: true
  doctest Mailapp

  import Swoosh.TestAssertions

  test "send email on user signup" do
    user = create_user(%{username: "Name", email: "example.name@gmail.com"})
    assert_email_sent Mailapp.UserEmail.welcome(user)
  end
end

I have followed the guidelines from https://github.com/swoosh/swoosh and https://hexdocs.pm/swoosh/Swoosh.html, yet I keep getting this error. Could someone please help me out?

Sh4dy
  • 143
  • 2
  • 15
  • Can you try port 587 or 465? – Dogbert Jan 05 '18 at 08:29
  • When I tried port 587, i got the following error:- `{:error, {:no_more_hosts, {:permanent_failure, 'smtp.gmail.com', :auth_failed}}}`. And when I tried port 465, I got:- `{:error, {:retries_exceeded, {:network_failure, 'smtp.gmail.com', {:error, :closed}}}}`. – Sh4dy Jan 05 '18 at 08:32
  • According to a GitHub discussion, the default port is 1025, so I used that in the first place. Here's the link to that discussion: https://github.com/swoosh/swoosh/issues/129. – Sh4dy Jan 05 '18 at 08:36

0 Answers0