Hello Monsieur/Madame.
Let's send that mail I mentioned two articles back.
In this app, I used one of the free SMTP mail providers named: MailGun.
Create your free account and create your API credentials to configure our app to send emails through MailGun server.
Now let's enter those credentials in our Rails app. As I've mentioned before we use the command,
bin/rails credentials:edit
Store your creds [:user_name, :password] for SMTP config under:
smtp:
user_name: <username_mailgun>
password: <password>
If you're using API instead of SMTP make sure to use the relevant credentials.
Save it and close.
Now your credentials are safe and is not passed on to your github repo if you put your code in there.
Get to config/environments/development.rb file in your app directory:
Now that your application is configured to use Mailgun API and also have a set UserMailer to send mails when a new user joins your application, it should work like a charm!
class UsersController < ApplicationController
# ...
def create
# ...
UserMailer.with(user: @user).welcome_email.deliver_later
end
end
If you are using a free account in MailGun just like me you may have to add the email account of the receiver to your account sandbox setting at mailgun.org.
Use something like TempMail to test your mailer.
You should receive the template mail/message you wrote in app/views/user_mailer/.html.erb or app/views/user_mailer/.text.erb.
There you go. EZ no!?
That's it for today. Thank you for reading!
Please subscribe to the newsletter for more fun af articles. Thank you!
Love,
M.
liked_the_post == true ? comment and share : comment and share