NoD*_*ame 22
我发现的最好的方法是使用mailman包.对于发送测试电子邮件,我使用我的gmail帐户使用以下配置mailman- >
def config do
%Mailman.Context{
config: %Mailman.SmtpConfig{ relay: "smtp.gmail.com",
port: 587,
username: "myusername@gmail.com",
password: "mypassword",
tls: :always },
composer: %Mailman.EexComposeConfig{}
}
end
Run Code Online (Sandbox Code Playgroud)
对于我使用以下内容的电子邮件内容:
def testing_email do
%Mailman.Email{
subject: "Hello Mailman!",
from: "myusername@gmail.com",
to: ["myotherusername@gmail.com"],
text: "Hello Mate",
html: Phoenix.View.render_to_string(MyApp.PageView,"index.html", foo: "bar")
}
end
Run Code Online (Sandbox Code Playgroud)
然后你就做 - >
1) email = MyApp.Mailer.deliver testing_email
2) Task.await(email)