2

如何使用 gem griddler 在 Rails 应用程序中接收电子邮件?

我按照这个链接:http ://sendgrid.com/blog/receiving-email-in-your-rails-app-with-griddler/

我的 index.html.erb posts_controller :

帖子

<% if @posts.count > 0 %>
<% @posts.each do |post| %>
<blockquote>
<p><%= post.body %></p>
<small><%= post.email %></small>
</blockquote>
<% end %>
<% else %>
<p><em>Oops, doesn't look like there are any posts yet.</em></p>
<% end %>

我的 config/initializer/griddler.rb :

Griddler.configure do |config|
  config.processor_class = EmailProcessor # MyEmailProcessor
  config.to = :hash # :full, :email, :token
  config.from = :email # :full, :token, :hash
  # :raw    => 'AppName <s13.6b2d13dc6a1d33db7644@mail.myapp.com>'
  # :email  => 's13.6b2d13dc6a1d33db7644@mail.myapp.com'
  # :token  => 's13.6b2d13dc6a1d33db7644'
  # :hash   => { raw: [...], email: [...], token: [...], host: [...],
# name: [...] }
  config.reply_delimiter = '-- REPLY ABOVE THIS LINE --'
  config.email_service = :sendgrid # :cloudmailin, :postmark, :mandrill, :mailgun
end

我的 lib/email_processor.rb :

class EmailProcessor
  def self.process(email)
    # all of your application-specific code here - creating models,
    # processing reports, etc
    Post.create!({ body: email.body, email: email.from })
  end
end

但是在索引帖子视图中没有从回调中得到任何东西,为什么?

4

1 回答 1

1

您必须在 sendgrid http://sendgrid.com/developer/reply上提供您网站的重定向 URL 。

如果您想提供 localhost URL,请使用https://ngrok.com/

于 2013-12-09T12:05:06.313 回答