Skip to content

Instantly share code, notes, and snippets.

@gonzafirewall
Created September 27, 2024 20:30
Show Gist options
  • Save gonzafirewall/9c1292f555c06cd52f20873a742bd45d to your computer and use it in GitHub Desktop.
Save gonzafirewall/9c1292f555c06cd52f20873a742bd45d to your computer and use it in GitHub Desktop.
Script enviador de Mail en elixir
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