Class OpenWFE::EmailNotificationParticipant
In: lib/openwfe/participants/enoparticipants.rb
Parent: MailParticipant

This participant is used to send an email notification.

It‘s perhaps better to use MailParticipant which is simpler to initialize. This class is anyway an extension of MailParticipant.

    @engine.register_participant(
        'eno',
        EmailNotificationParticipant.new(
            "googlemail.l.google.com",
            25,
            "[email protected]",
            """Subject: test 0

    0 : ${r:Time.new}
    1 : ${f:customer_name}
            """))

And then, from the process definition :

    class TestDefinition0 < OpenWFE::ProcessDefinition
        def make
            process_definition :name => "test0", :revision => "0" do
                sequence do
                    set :field => 'email_target' do
                        "[email protected]"
                    end
                    set :field => 'customer_name' do
                        "Monsieur Toto"
                    end
                    participant :ref => 'eno'
                end
            end
        end
    end

The ‘template’ parameter may contain an instance of File instead of an instance of String.

    @engine.register_participant(
        'eno',
        EmailNotificationParticipant.new(
            "googlemail.l.google.com",
            25,
            "[email protected]",
            File.new("path/to/my/mail/template.txt")))

You can also define the email template as a Ruby block :

    p = EmailNotificationParticipant.new("googlemail.l.google.com", 25, "[email protected]") do | flowexpression, participant, workitem |

        # generally, only the workitem is used within a template

        s = ""

        # the header of the message

        s << "Subject: #{workitem.subject}\n\n"

        # then, the body

        workitem.attributes.each do |key, value|
            s << "- '#{k}' => '#{value}'\n"
        end
        s << "\ndone.\n"
    end

Note that the template integrates the subject and requires then a double newline before the message body.

Methods

new  

Public Class methods

Create a new email notification participant. Requires a mail server, port, a from address, and a mail message template

[Source]

     # File lib/openwfe/participants/enoparticipants.rb, line 217
217:         def initialize (
218:             smtp_server, smtp_port, from_address, template=nil, &block)
219: 
220:             params = {}
221:             params[:smtp_server] = smtp_server
222:             params[:smtp_port] = smtp_port
223:             params[:from_address] = from_address
224: 
225:             params[:template] = template if template
226: 
227:             super(params, &block)
228:         end

[Validate]