Note that there are some explanatory texts on larger screens.

plurals
  1. POMailer: Sending emails using Ruby on Rails failing
    primarykey
    data
    text
    <p>I have created a database of users in my Ruby on Rails app, and now I'm trying to create a mailer that send emails to all users in my database whenever I want.</p> <p>Here's my model:</p> <pre><code>class MailMessage &lt; ActionMailer::Base def contact(recipient, subject, message) # host = Hobo::Controller.request_host # app_name = Hobo::Controller.app_name || host @subject = subject # @body = { :user =&gt; user, :host =&gt; host, :app_name =&gt; app_name } @body["title"] = 'This is title' @body["email"] = 'mark@doc.org.uk' @body["message"] = message @recipients = recipient @from = 'no-reply@doc.org.uk' @sent_on = Time.now @headers = {} end end </code></pre> <p>Here's my controller:</p> <pre><code>class MailMessageController &lt; ApplicationController def sendmail email = @params["email"] recipient = email["recipient"] subject = email["subject"] message = email["message"] MailMessage.deliver_contact(recipient, subject, message) return if request.xhr? render :text =&gt; 'Message sent successfully' end def index render :file =&gt; 'app/views/mail_message/index.html' end end </code></pre> <p>Here's my <code>views/mail_message</code>:</p> <pre><code>&lt;h1&gt;Send Email&lt;/h1&gt; &lt;%= form_tag :action =&gt; 'sendmail' %&gt; &lt;p&gt; &lt;label for="email_subject"&gt;Subject&lt;/label&gt; &lt;%= text_field 'email', 'subject' %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="email_recipient"&gt;Recipient&lt;/label&gt; &lt;%= text_field 'email', 'recipient' %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="email_message"&gt;Message&lt;/label&gt; &lt;%= text_area 'email', 'message' %&gt; &lt;/p&gt; &lt;%= submit_tag "Send" %&gt; &lt;%= form_tag %&gt; </code></pre> <p>Here's my <code>enviroment.rb</code>:</p> <pre><code>ActionMailer::Base.delivery_method = :sendmail ActionMailer::Base.sendmail_settings = { :location =&gt; '/usr/sbin/sendmail', :arguments =&gt; '-i -t' } ActionMailer::Base.perform_deliveries = true # the "deliver_*" methods are available ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.default_charset = "utf-8" ActionMailer::Base.default_content_type = "text/html" # default: "text/plain" ActionMailer::Base.default_mime_version = "1.0" ActionMailer::Base.default_implicit_parts_order = [ "text/html", "text/plain"] </code></pre> <p>When I run a test message, I get the following error:</p> <pre><code>You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] app/controllers/mail_message_controller.rb:4:in `sendmail' </code></pre> <p>It doesn't seem to recognise <code>sendmail</code>, but I have given its location. Any clues for how to fix this error will be very appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload