Ask A Question

Notifications

Youโ€™re not receiving notifications from this thread.

Sending Emails with SMTP and Sendgrid Discussion

jajajaj Chris Your the man. I was just switching from my simple gmail account to using sendgrid and now this episode show up. :) very very happy.

Reply

Let's pretend I planned that. ๐Ÿ˜‰

Reply

Hi Chris, you are a cool dude, keep up the good work

Reply

Thanks man! :)

Reply

can we use mailer to send message like in a web contact form without saving the message into the database?

Reply

So grateful for this help. Thank you!

Reply

You're the man Chris! Thanks for this

Reply

You're welcome! ๐ŸŽ‰

Reply

Could you show us how you would tie this into a contact form?

Reply
Alejandro Ventura Alejandro Ventura

Where do I need to customize the email layout and whats the best practice to design email's layouts? In order to send my logo and maybe some links and so on! I want my emails look pretty instead of just plain text!

Reply

Unfortunately, styling emails is still pretty nasty these days. You generally will see people using tables to do layouts because email applications don't generally support the full CSS suite of features for various reasons (including security). Lots to find if you google "html emails" or "email layouts".

As for images, Rails lets you include them as normal, but you have to specify the asset host: http://edgeguides.rubyonrai...

Reply

Hi Chris. First of all, thanks for putting this out, GoRails has been a great resource to implement new features and learn.

I've got a file in my model that gets upload with Shrine to S3 (works perfectly) and I was wondering how can I attach that file when sending email with a Mailer?

Reply

Adding an attachment in your mailers is just as simple as doing:

attachments['file-name.jpg'] = @model.upload

The right side should just a be a File-like object that Rails then assign to the filename in the email.

Reply

Hi Chris i am getting uninitialized constant NotificationMailer , not sure why

irb(main):001:0> NotificationMailer.welcome.deliver_now
Traceback (most recent call last):
        1: from (irb):1
NameError (uninitialized constant NotificationMailer)

i am using rails 6,

Reply

Try to reload! your console

Reply

Hi Chris, thank you so much for GoRails, I really appreciate the effort and the work you put on the content you are sharing.

I have trouble with Sendgrid and sending mail from devise using Templates I created in Sendgrid. So I just want to design templates in Sendgrid and then call them from my devise mailer. Been struggling with this and was wondering if you have any comments on it.

Reply

You'll need to use their API to do that. Check out this gem: https://github.com/eddiezane/sendgrid-actionmailer

Reply

Awesome thank you so much will do.

Much appreciated.

Reply

Hi Chris, can we use this sendgrid with Devise?

Reply

Yep! Devise just uses whatever email host you have configured with Actionmailer.

Reply

Great! Thanks for your prompt reply. I was watching your video and just noticed you already replied!

Reply

Hi Chris, sorry to bother you again. It seems like I cannot find secrets.yml in my Rails app. Is it because I am using Rails 6?

Reply

Hi Chris,

for some weird reason my attempt to send is taking 60 seconds + i'm not getting any error (or anything obviuous), have you experienced this?

```irb(main):004:0> NotificationMailer.welcome.deliver_now
Rendering notification_mailer/welcome.html.erb within layouts/mailer
Rendered notification_mailer/welcome.html.erb within layouts/mailer (Duration: 0.3ms | Allocations: 81)
NotificationMailer#welcome: processed outbound mail in 3.0ms
Delivered mail 5ed7d1bc53d59_5243ff1f6436e6c235e1@Deargs-MBP.mail (60054.4ms)
Date: Wed, 03 Jun 2020 17:37:16 +0100
From: removed
To: removed
Message-ID: <5ed7d1bc53d59_5243ff1f6436e6c235e1@Deargs-MBP.mail>
Subject: welcome to our app
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>



<br> /* Email styles need to be inline */<br>


Welcome!



=> #, , , >, , , , >

Reply

Amazing, Chris, it just works. I needed only to move to use credentials as I'm on Rails 6.0.3.2 but apart from that it worked beautifully, thanks for the great sharing. Cheers!

Reply

This helped me so much. Thanks a lot!!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,168+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.