1

だから私はActionMailerメーラーを手に入れました

class ReportMailer < ActionMailer::Base
  def notify_doctor_of_updated_document(document)
    recipients  document.user.email_id
    from        "(removed for privacy)"
    subject     "Document #{document.document_number} has been updated and saved as #{document.status}"
    sent_on     Time.now
    body        :document => document
  end
end

そしてビューは

Document
<%= @document.class %>

しかし、走っているとき

>> d = Document.last
=> #<Document id: "fff52d70-7ba2-11de-9b70-001ec9e252ed", document_number: "ABCD1234", procedures_count: 0, user_id: "630", created_at: "2009-07-28 18:18:07", updated_at: "2009-08-30 20:59:41", active: false, facility_id: 94157, status: "incomplete", staff_id: nil, transcriptionist_id: nil, job_length: nil, work_type: nil, transcription_date: nil, non_trans_edit_date: nil, pervasync_flag: true, old_id: nil>
>> ReportMailer.deliver_notify_doctor_of_updated_document(d)
=> #<TMail::Mail port=#<TMail::StringPort:id=0x8185326c> bodyport=#<TMail::StringPort:id=0x8184d6b4>>

コンソールから、これはログに出力されます

Sent mail to (removed for privacy)

Date: Tue, 11 May 2010 20:45:14 -0500
From: (removed for privacy)
To: (removed for privacy)
Subject: Document ABCD1234 has been updated and saved as incomplete
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4bea082ab4ae8_aa4800b81ac13f5


--mimepart_4bea082ab4ae8_aa4800b81ac13f5
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

Document
NilClass=

--mimepart_4bea082ab4ae8_aa4800b81ac13f5--
4

1 に答える 1

1

コントローラーのアクションを表示してください。私の最近のアプリケーションの例の 1 つがこれです。

class UserMailer < ActionMailer::Base  
  # Submission email
  def submission_batch(batch)
    recipients  batch.user.email
    from        "webmaster@gmail.com"
    subject     "Thank you for submitting a batch"
    body        :batch => batch
  end 
end

コントローラーのアクション/メソッドは

def update_samp
    @batch = Batch.find(params[:id])

     respond_to do |format|
       if @batch.update_attributes(params[:batch])
         UserMailer.deliver_submission_batch(@batch)
         flash[:success] = 'Batch and Sample details were successfully stored and an automated email briefing the details have been sent to your email. '
         format.html { redirect_to(@batch) }         
         format.xml  { head :ok }
       else
         format.html { render :action => "sample_production" }
         format.xml  { render :xml => @batch.errors, :status => :unprocessable_entity }
       end
     end
  end

そして、私の見解は次のとおりです

Hi <%= @batch.user.name %>
 and further you describe the email 

ここで、確認するために言及したいことがあります。

  1. SMTP 設定を確認します。メールの送信にはGmailを使用しています。開発環境と本番環境で設定をセットアップしました。

  2. 送信する変数の名前/スペルを確認してください。

  3. html.erb ファイルが user_mailer.rb で定義されたメソッドと同じ名前であることを確認してください

これらが役立つことを願っています。

乾杯

于 2012-05-23T10:45:28.210 に答える