简体   繁体   English

ActionMailer自动电子邮件。 Ruby on Rails

[英]ActionMailer automatic emails. Ruby on Rails

Building A "Ticketing System" for our support team, so they can create tickets when a customer calls and requests something. 为我们的支持团队建立一个“票务系统”,以便他们可以在客户打电话和提出要求时创建票证。

I have quite a lot up and running, now I need each time a ticket is created for the app to send an email to the person the the ticket is assigned to. 我的工作量很大,现在,每次为应用程序创建票证时,我都需要向该票证分配的人发送电子邮件。 This info is all in the DB and accessible easily. 此信息全部在数据库中,可以轻松访问。

Do you guys have any suggestion how I can imolement this or any documentation I can use? 你们对我如何执行此建议或我可以使用的任何文档有任何建议吗?

Thanks! 谢谢!

Check out this Railscast to get started on your mailer - http://railscasts.com/episodes/206-action-mailer-in-rails-3 看看这个Railscast上手你的邮件- http://railscasts.com/episodes/206-action-mailer-in-rails-3

Basically, in your Ticket create method, you want to call the mailer and pass in the email of the assigned person so that every time a Ticket is created, it sends an email. 基本上,在工单create方法中,您要呼叫邮件程序并传递分配人的电子邮件,以便每次创建工单时都会发送一封电子邮件。

# Model
class Ticket

  ...
  after_create: :send_email
  ...

  def send_email
    Mailer.delay_for(5.minutes).send_ticket(id, assigned_to.id) # delay sending e-mail
    Mailer.send_ticket(id, assigned_to.id).deliver # or send it now..
  end
end

class Mailer < ActionMailer::Base

  def send_ticket(ticket_id, assigned_to_id)
    @assigned_to = User.find(assigned_to_id)
    @ticket = Ticket.find(ticket_id)
    mail(
      from: 'you<do-not-reply@your_domain.com>',
      to: @assigned_to.email,
      subject: 'new assignment'
    )
  end
end

this is mainly the logic, now for the views add the following file app/views/mailer/send_ticket.html.haml 这主要是逻辑,现在为视图添加以下文件app/views/mailer/send_ticket.html.haml

Hey #{@assigned_to.name},
%p you have been assigned to a new ticket #{@ticket.id}
%p here is the link to the ticket #{@ticket.url}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM