将 SendGrid 与 Heroku 连接
Connecting SendGrid with Heroku
我创建了一个新的 Action Mailer,当有人点击 "Click to Connect" 按钮时,我会收到电子邮件通知。我正在学习教程,并且能够通过我的 "contact us" 按钮在 Heroku 上成功建立与 SendGrid 的连接。目前,当我单击该按钮时,它会打开我计算机的电子邮件应用程序,而不是触发 SendGrip 应用程序。
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
}
更新:我需要 users/show.html.erb 底部的按钮将用户发送到此表单,而不是打开我的电子邮件应用程序。然后这个页面的按钮需要连接到SendGrid。
views/connections/new.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">Let's Connect</h1>
<h5 class="text-center">I'd like to connect with...</h5>
<div class="well">
<%= form_for @connection do |f| %>
<div class="form-group">
<%= f.label :your_name, "Your Name" %>
<%= f.text_field :your_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email, "Your Email" %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments, "Connection's Name" %>
<%= f.text_area :connections_name, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>
你应该在控制器中制作一个表单和post表单参数到一个动作,下面的post有你需要的一切:Contact Form Mailer in Rails 4
你应该从 href 中删除 mailto
<a class="btn btn-primary btn-lg btn-block active"
href="mailto:connections@jrdevmentoring.com" role="button">Click to Connect</a>
这就是打开电子邮件应用程序的原因
我创建了一个新的 Action Mailer,当有人点击 "Click to Connect" 按钮时,我会收到电子邮件通知。我正在学习教程,并且能够通过我的 "contact us" 按钮在 Heroku 上成功建立与 SendGrid 的连接。目前,当我单击该按钮时,它会打开我计算机的电子邮件应用程序,而不是触发 SendGrip 应用程序。
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
}
更新:我需要 users/show.html.erb 底部的按钮将用户发送到此表单,而不是打开我的电子邮件应用程序。然后这个页面的按钮需要连接到SendGrid。
views/connections/new.html.erb
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1 class="text-center">Let's Connect</h1>
<h5 class="text-center">I'd like to connect with...</h5>
<div class="well">
<%= form_for @connection do |f| %>
<div class="form-group">
<%= f.label :your_name, "Your Name" %>
<%= f.text_field :your_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email, "Your Email" %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments, "Connection's Name" %>
<%= f.text_area :connections_name, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
</div>
</div>
</div>
你应该在控制器中制作一个表单和post表单参数到一个动作,下面的post有你需要的一切:Contact Form Mailer in Rails 4
你应该从 href 中删除 mailto
<a class="btn btn-primary btn-lg btn-block active"
href="mailto:connections@jrdevmentoring.com" role="button">Click to Connect</a>
这就是打开电子邮件应用程序的原因