Class: OpenWFE::MailParticipant
- Inherits:
-
Object
- Object
- OpenWFE::MailParticipant
- Includes:
- LocalParticipant, TemplateMixin
- Defined in:
- lib/openwfe/participants/enoparticipants.rb
Overview
MailParticipant is a simplification of EmailNotificationParticipant.
It’s initialized in this way :
p = MailParticipant.new(
:smtp_server => "mailhost.ourcompany.co.jp",
:from_address => "[email protected]",
:template => "Dear ${f:name}, you've got mail")
or
p = MailParticipant.new(
:smtp_server => "mailhost.ourcompany.co.jp",
:smtp_port => 25,
:from_address => "[email protected]"
) do |workitem|
s = ""
s << "Dear #{workitem.name},\n"
s << "\n"
s << "it's #{Time.new.to_s} and you've got mail"
s
end
As with EmailNotificationParticipant, the “to” address for your email is taken from the workitem’s email_target field. So, to have the email sent to “[email protected]”, set your workitem’s email_target field to “[email protected]” prior to feeding it to the mail participant.
Likewise, you can also override the :from_address value by setting the workitems email_from field.
When passing the mail template as a block, you have four possible arities :
{ |workitem| ... }
{ |participant_expression, workitem| ... }
{ |participant_expression, participant_instance, workitem| ... }
{ ... }
The smtp server and host default to “127.0.0.1” / 25.
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Contextual
Instance Method Summary collapse
-
#consume(workitem) ⇒ Object
The method called each time a workitem reaches this participant.
-
#initialize(params, &block) ⇒ MailParticipant
constructor
A new instance of MailParticipant.
Methods included from TemplateMixin
Methods included from LocalParticipant
#call_block, #get_flow_expression, #reply_to_engine
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Methods included from OwfeServiceLocator
#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator
Constructor Details
#initialize(params, &block) ⇒ MailParticipant
Returns a new instance of MailParticipant.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/openwfe/participants/enoparticipants.rb', line 95 def initialize (params, &block) @smtp_server = params[:smtp_server] @smtp_port = params[:smtp_port] @from_address = params[:from_address] @template = params[:template] @block_template = block # some defaults @smtp_server = "127.0.0.1" unless @smtp_server @smtp_port = 25 unless @smtp_port end |
Instance Method Details
#consume(workitem) ⇒ Object
The method called each time a workitem reaches this participant
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/openwfe/participants/enoparticipants.rb', line 113 def consume (workitem) fe = get_flow_expression(workitem) to_address = workitem.email_target # # 1. Expand variables msg = eval_template workitem from_address = workitem.email_from rescue @from_address #puts "msg >>>\n#{msg}<<<" # # 2. Send message Net::SMTP.start(@smtp_server, @smtp_port) do |smtp| smtp.(msg, from_address, to_address) end # # 3. Reply to engine reply_to_engine(workitem) end |