use*_*042 2 email incoming-mail ruby-on-rails-3 mailman-gem
我在rails3应用程序上开发ruby,我正在向用户发送电子邮件,如果用户回复该电子邮件然后回复内容,则日期应更新到数据库.为此,我有ProductComment模型.当admin向用户发送评论时,它将存储在数据库中.如果用户回复,则应相应地更新数据库.我正在尝试使用mailman.我已经安装了宝石.但是我没有得到如何获得评论ID,我应该在回复地址写什么,在哪里写邮件员代码以及从哪个邮件我应该阅读.
我发送这样的电子邮件:
mail(:to => @user.email, :subject => "Edit Your Product", :reply_to=>"abc@syz.com)
Run Code Online (Sandbox Code Playgroud)
我在产品控制器中处理它,如下所示:
require 'mailman'
Mailman::Application.run do
to 'abc@xyz.com' do
ProductComment.create(message)
end
end
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题
请告诉我如何在rails3应用程序中使用ruby中的mailman gem
有一个关于在有轨电视上收到邮件的电子邮件的最新专题节目:http: //railscasts.com/episodes/313-receiving-email-with-mailman
chmod +x script/mailman_server
cat mailman_test.eml | script/mailman_server
script/mailman_server
Run Code Online (Sandbox Code Playgroud)
-
# script/mailman_server
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"
Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.pop3 = {
server: 'pop.gmail.com', port: 995, ssl: true,
username: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
Mailman::Application.run do
default do
begin
Ticket.receive_mail(message)
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
end
Run Code Online (Sandbox Code Playgroud)
-
def self.receive_mail(message)
ticket_id = message.subject[/^Update (\d+)$/, 1]
if ticket_id.present? && Ticket.exists?(ticket_id)
Ticket.update(ticket_id, body: message.body.decoded)
else
Ticket.create subject: message.subject, body: message.body.decoded, from: message.from.first
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2360 次 |
| 最近记录: |