Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send emails with Phoenix framework

What is the best and most convinient way to send emails using Phoenix framework?

like image 331
NoDisplayName Avatar asked Aug 14 '15 13:08

NoDisplayName


People also ask

Can you email in R code?

blastula allows you to create and send e-mails using R. It works similarly to the Shiny package, but instead of writing R code to create an interactive application, you write R code to create an HTML e-mail that can be rendered across a wide variety of e-mail providers.

Can you use JavaScript to send an email?

You can't send emails using JavaScript code alone due to lack of support for server sockets. For this, you need a server-side language that talks to the SMTP server. You can use JS in conjunction with a server script that will send emails from the browser based on your requests.

Is Phoenix framework fast?

For any company that currently uses Ruby on Rails, Phoenix Framework should be on your radar, because it adds considerable performance gains. To top that off, Phoenix makes it incredibly fast to build web applications.


1 Answers

The best way I've found is to use the mailman package. For sending test emails I was using my gmail account using the following config for mailman ->

def config do
  %Mailman.Context{
   config: %Mailman.SmtpConfig{ relay: "smtp.gmail.com",                 
                                port: 587,
                                username: "[email protected]",
                                password: "mypassword",
                                tls: :always },                                            
   composer: %Mailman.EexComposeConfig{}
  }
end

and for the email content I was using the following:

def testing_email do
    %Mailman.Email{
      subject: "Hello Mailman!",
      from: "[email protected]",
      to: ["[email protected]"],          
      text: "Hello Mate",
      html: Phoenix.View.render_to_string(MyApp.PageView,"index.html", foo: "bar")
      }
end

and then you just do ->

1) email = MyApp.Mailer.deliver testing_email

2) Task.await(email)

like image 135
NoDisplayName Avatar answered Sep 21 '22 18:09

NoDisplayName