anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
178 stars 72 forks source link

Couldn't get rails to send an email using the example #308

Closed fredsdc closed 1 year ago

fredsdc commented 1 year ago

I tried to have a workflow send an email, using the given example and it gives the following error: undefined method `custom_email' for Mailer:Class

Do this still work?

picman commented 1 year ago

Yes, it does. See the Wiki. You should call CustomWorkflowMailer.deliver_custom_email(issue.author, 'Subject', 'Body')

piotrsz772 commented 1 year ago

I have an error like this

Workflow script executable before saving observable object contains error: undefined local variable or methodissue' for # Did you mean? @issue `

but when i use @issue not working

picman commented 1 year ago

What is the observable object? How about self.issue?

piotrsz772 commented 1 year ago

Observable object is issue self.issue not working too

piotrsz772 commented 1 year ago

image

picman commented 1 year ago

If the observable object is Issue, you can directly call its methods, so simply author instead of self.issue.author.

piotrsz772 commented 1 year ago

Ok, it works for author issue but if i want to send email to selected email on the picture? There is a way?

image

picman commented 1 year ago

The first argument of the function must be a user. So you cannot sent an email to an email address but to a certain Redmine user only. As a workaround you can create a user with the given email address and then use them as the email recipient.

piotrsz772 commented 1 year ago

Yeah I did this, it is very nice plugin and simple but need some time to understand :) Thank you very much for your help.

piotrsz772 commented 1 year ago

How can I set for Body html value?

fredsdc commented 1 year ago

I had a similar problem. Finally I used ActionMailer to build and send the mail out of Redmine constraints.

Where: content_bh -> html of the body content_bp -> text of the body mail_to -> to mail_cc -> cc content -> subject tags -> tags for which attachments to include, search in description

html_part = Mail::Part.new do
  content_type  'text/html; charset=UTF-8'
  body content_bh   
end

text_part = Mail::Part.new do
  body content_bp   
end

m=ActionMailer::Base.mail(
  from: User.current.mail,
  to: mail_to,
  cc: mail_cc,
  subject: content,
  body: '',
  content_type: "multipart/mixed"
)

self.attachments.select{|a| a.description.downcase.match?(tags.downcase)}.each do |a|
  m.attachments[a.filename]=File.read(a.diskfile)
end

m.part content_type: "multipart/alternative" do |p|
  p.html_part = html_part
  p.text_part = text_part
end

m.deliver_now
picman commented 1 year ago

You can use html_safe function:

recipient = User.find(9)
CustomWorkflowMailer.deliver_custom_email(recipient, 
                                          'Subject', 
                                          '<b>Body</b>'.html_safe)