我正在尝试编写一个使用Swoosh库发送电子邮件的Elixir代码。出于某种原因,我不断收到以下错误: -
{:error,
{:retries_exceeded, {:network_failure, 'smtp.gmail.com', {:error, :timeout}}}}
这就是我的终端的样子: -
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
我的config\config.exs
文件如下所示: -
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
我的lib\mailapp.ex
文件如下所示: -
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
我的test\mailapp_test.exs
文件如下所示: -
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
我已遵循https://github.com/swoosh/swoosh和https://hexdocs.pm/swoosh/Swoosh.html的指南,但我一直收到此错误。有人可以帮帮我吗?