lundi 28 décembre 2015

Connecting SendGrid with Heroku

I have created a new Action Mailer that will allow me to be notified by email when someone clicks on the "Click to Connect" button. I'm following a tutorial and was able to successfully set up the connection with SendGrid on Heroku from my "contact us" button. Currently when I click the button it opens my computer's email app instead of triggering the SendGrip app.

users/show.html.erb

<div class='container'>
<div class='row'>
    <div class='col-md-3 text-center'>
        <%= image_tag @user.profile.avatar.url, class: 'user-show-avatar' %>
    </div>
    <div class='col-md-6'>
        <h1><%= @user.profile.first_name %></h1>
        <h3><%= @user.profile.city %>, <%= @user.profile.state %>, <%= @user.profile.country %></h3>
        <div class='well profile-block profile-description'>
            <h4>Bio</h4>
            <p><%= @user.profile.bio %></p>
            <h4>Coding Languages</h4>
            <p><%= @user.profile.coding_languages %></p>
            <h4>Mentoring Needs</h4>
            <p><%= @user.profile.mentoring_needs %></p>
        </div class='connect_button'>
        <a class="btn btn-primary btn-lg btn-block active" href="mailto:connections@jrdevmentoring.com" role="button">Click to Connect</a>
    </div>
</div>

mailers/connection_mailer.rb

class ConnectionsMailer < ActionMailer::Base
    default to: 'connections@jrdevmentoring.com'

    def connection_email(name, email, body)
        @name = name
        @email = email
        @body = body
        mail(from: email, subject: 'Jr. Dev Mentoring Connect Form Message')
    end
end

config/environment.rb

# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!

ActionMailer::Base.smtp_settings = {
  :address => 'smtp.sendgrid.net',
  :port => '587',
  :authentication => :plain,
  :user_name => ENV['SENDGRID_USERNAME'],
  :password => ENV['SENDGRID_PASSWORD'],
  :domain => 'heroku.com',
  :enable_startstls_auto => true
}

Aucun commentaire:

Enregistrer un commentaire