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

Please could you show your controller actions. One of my example in my recent application is this.

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

The controller action/method is

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

And then my View is as follows

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

Now there are things which I would like to mention to check.

  1. Check your smtp settings. I use Gmail for sending mails. I have my settings set up in the development and production environment.

  2. Check the names/spellings of the variables you send.

  3. Make sure the html.erb file is the same name as the method defined in the user_mailer.rb

Hope these things help.

Cheers

于 2012-05-23T10:45:28.210 回答