Class | MailSenderController
In: | app/controllers/mail_sender_controller.rb
Parent: | ApplicationController

メール送信を実装する。

### Methods

deliver post

### Public Instance methods

deliver()

メール履歴から取り出し配送に回す。

[Source]

        # File app/controllers/mail_sender_controller.rb, line 46
    46:   def deliver
    47:     if mail_history = MailHistory.find(params[:id])
    48:       render :text => mail_history.deliver
    49:       return
    50:     end
    51:   end

post()

メールキューから取り出し配送に回す。

[Source]

        # File app/controllers/mail_sender_controller.rb, line 6
     6:   def post
     7:     queue = MailQueue.find(params[:id], :include => [ :product, :from ])
     8:     if queue.processed?
     9:       logger.warn { "WARN: MailQueue #{queue.id} was already processed." }
    10:       render :text => "true"
    11:       return
    12:     end
    13:     from = queue.from
    14:     User.current = from
    15:     product = queue.product
    16:     document = queue.document
    17:     comment = queue.comment_message
    18:     mail_format = MailFormat.find_by_mail_mode(queue.mail_mode)
    19:     recipients = queue.recipients
    20:     MailHistory.transaction do
    21:       recipients.each do |recipient|
    22:         if user = recipient.user
    23:           url = url_for(:controller => "user", :action => "auto", :id => queue.id, :u => user.login)
    24:           set_locale(recipient.last_language)
    25:           formatted = mail_format.format_all(product, document, from, recipient, url, comment)
    26:           mail_history = MailHistory.create!({
    27:             :mail_queue => queue,
    28:             :from_value => "#{formatted[:from]} <#{from.mail_address}>",
    29:             :recipient_value => "#{formatted[:recipient]} <#{recipient.mail_address}>",
    30:             :subject => formatted[:subject],
    31:             :body => formatted[:body],
    32:             :status => "queue",
    33:           })
    34:           mail_history.deliver
    35:         end
    36:       end
    37:       queue.processed = true
    38:       queue.save!
    39:     end
    40:     render :text => "true"
    41:   ensure
    42:     set_locale(nil)
    43:   end

[Validate]