0

I have an app where users can sign up for workshops and admin has a possibility to write an e-mail to all the participants through the app. The fragment of code to send mail message to the group looks like this

workshop.students_all.each do |user|
  WorkshopNotifyGroupMailer.notify_user(user, workshop, subject, body).deliver_later
end

so it's nothing extraordinary (User and Workshops are instances of models).

Now, I wanted to add one additional e-mail address to be sent each time a group is notified (just to have a copy how does the sent mail look like). I thought of doing it something like that (to keep the code short):

admin = OpenStruct.new(email: 'admin@email.com', first_name: 'Nameless') #These are fields taken from User instance by mailer
WorkshopNotifyGroupMailer.notify_user(admin, workshop, subject, body).deliver_later

Unfortunately, I receive "Unsupported argument type: OpenStruct" error. Is there a way to send an e-mail which uses an instance of a model using some kind of artificial structure? (In this case just assume admin is not on the user list and won't be)

bochen421
  • 161
  • 3
  • 14
  • I believe the error "Unsupported argument type: OpenStruct" is because (assuming this is DelayedJob) `DelayedJob` tries to find the objects (in DB) passed in the arguments at the time when actually running the mailer. And `OpenStruct` is a temporary object. You can't find it in DB with some ID. Instead, you can pass all the required attributes individually in the method OR as a Hash of attributes. – Jagdeep Singh Mar 14 '18 at 07:31
  • Could you provide your NotifyGroupMailer code? – GorillaApe Mar 14 '18 at 07:33

0 Answers0