Created
September 27, 2024 20:30
-
-
Save gonzafirewall/9c1292f555c06cd52f20873a742bd45d to your computer and use it in GitHub Desktop.
Script enviador de Mail en elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mix.install([:swoosh, :hackney, :mail]) | |
Application.put_env(:myapp, Prueba.Mailer, adapter: Swoosh.Adapters.Gmail, access_token: {:system, "GMAIL_API_ACCESS_TOKEN"}) | |
Application.put_env(:myapp, :email_conf, to_mail: "[email protected]", from_mail: "[email protected]") | |
defmodule Prueba.Mailer do | |
use Swoosh.Mailer, otp_app: :myapp | |
end | |
defmodule Prueba.Enviador do | |
import Swoosh.Email | |
def enviar do | |
email_conf = Application.get_env(:myapp, :email_conf) | |
IO.puts(email_conf[:to_mail]) | |
email = new() | |
|> to({"Prueba", email_conf[:to_mail] }) | |
|> from({"Prueba", email_conf[:from_mail] }) | |
|> subject("Holaa!") | |
|> html_body("<h1>Hello Prueba</h1>") | |
|> text_body("Hello Prueba\n") | |
Prueba.Mailer.deliver(email) | |
end | |
end | |
Prueba.Enviador.enviar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment