Ruby on Rails Friday, September 15, 2017

OK, I realised what was wrong.  This was code I got from somewhere else and it does not actually send the email.  So I have done a direcrent version but still having problems.

irb(main):067:0* class MyMailer < ActionMailer::Base
irb(main):068:1>   def test_email
irb(main):069:2>     @recipients  = "meemail@funkytwig.com"
irb(main):070:2>     @from        = "otheremail@eventpuddle.com"
irb(main):071:2>     @subject     = "This is a subject"
irb(main):072:2>     @body        = "This is the body"
irb(main):073:2>
irb(main):074:2*     mail(:to => @recipients, :subject => @subject, :body => @body )
irb(main):075:2>   end
irb(main):076:1> end
=> :test_email
irb(main):077:0>
irb(main):078:0* my_mailer = MyMailer.new
=> #<MyMailer:0x007fcbe6bca9a8 @_routes=nil, @_action_has_layout=true, @_mail_was_called=false, @_message=#<Mail::Message:70256863106160, Multipart: false, Headers: >>
irb(main):079:0>
irb(main):080:0* my_mailer.delivery_method = :smtp
=> :smtp
irb(main):081:0> my_mailer.smtp_settings = {
irb(main):082:1*     user_name:      'user',
irb(main):083:1*     password:       'pass',
irb(main):084:1*     domain:         'mail.xtreamlab.net',
irb(main):085:1*     address:        'mail.xtreamlab.net',
irb(main):086:1*     port:           '25',
irb(main):087:1*     authentication: :plain,
irb(main):088:1*     enable_starttls_auto: true
irb(main):089:1> }
=> {:user_name=>"user", :password=>"pass", :domain=>"mail.xtreamlab.net", :address=>"mail.xtreamlab.net", :port=>"25", :authentication=>:plain, :enable_starttls_auto=>true}
irb(main):090:0>
irb(main):091:0* my_mailer.test_email
NoMethodError: undefined method `com"' for nil:NilClass
    from (irb):69:in `test_email'
    from (irb):91
irb(main):092:0>

Bit confused here, no idea what com is.

Ben

PS just posting the plain code below as it may be easier to read.

class MyMailer < ActionMailer::Base
  def test_email
    @recipients  = "
meemail@funkytwig.com"
    @from        = "otheremail@eventpuddle.com"
    @subject     = "This is a subject"
    @body        = "This is the body"

    mail(:to => @recipients, :subject => @subject, :body => @body )
  end
end

my_mailer = MyMailer.new

my_mailer.delivery_method = :smtp
my_mailer.smtp_settings = {
    user_name:      'user',
    password:       'pass',
    domain:         'mail.xtreamlab.net',
    address:        'mail.xtreamlab.net',
    port:           '2525',
    authentication: :plain,
    enable_starttls_auto: true
}

my_mailer.test_email

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d9cc161f-45bb-41a4-bec7-4de3fbe2494e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment