【问题标题】:Connecting SendGrid with Heroku连接 SendGrid 和 Heroku
【发布时间】:2016-04-02 15:29:05
【问题描述】:

我创建了一个新的 Action Mailer,当有人点击“点击连接”按钮时,我可以通过电子邮件收到通知。我正在学习一个教程,并且能够通过我的“联系我们”按钮在 Heroku 上成功建立与 SendGrid 的连接。目前,当我单击该按钮时,它会打开我计算机的电子邮件应用程序,而不是触发 SendGrip 应用程序。

用户/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。

视图/连接/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>

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3 heroku sendgrid


【解决方案1】:

您应该制作一个表单并将表单参数发布到控制器中的操作,以下帖子有您需要的一切:Contact Form Mailer in Rails 4

【讨论】:

  • 我按照你提供的链接和其他人没有成功
【解决方案2】:

你应该从 href 中删除 mailto

<a class="btn btn-primary btn-lg btn-block active" 
href="mailto:connections@jrdevmentoring.com" role="button">Click to Connect</a>

这就是打开电子邮件应用程序的原因

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 2013-01-08
    • 2012-09-14
    • 2013-10-28
    • 1970-01-01
    相关资源
    最近更新 更多