Class | OpenWFE::MailParticipant |
In: |
lib/openwfe/participants/enoparticipants.rb
|
Parent: | Object |
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.
# File lib/openwfe/participants/enoparticipants.rb, line 95 95: def initialize (params, &block) 96: 97: @smtp_server = params[:smtp_server] 98: @smtp_port = params[:smtp_port] 99: @from_address = params[:from_address] 100: @template = params[:template] 101: 102: @block_template = block 103: 104: # some defaults 105: 106: @smtp_server = "127.0.0.1" unless @smtp_server 107: @smtp_port = 25 unless @smtp_port 108: end
The method called each time a workitem reaches this participant
# File lib/openwfe/participants/enoparticipants.rb, line 113 113: def consume (workitem) 114: 115: fe = get_flow_expression(workitem) 116: to_address = workitem.email_target 117: 118: # 119: # 1. Expand variables 120: 121: msg = eval_template workitem 122: 123: from_address = workitem.email_from rescue @from_address 124: 125: #puts "msg >>>\n#{msg}<<<" 126: 127: # 128: # 2. Send message 129: 130: Net::SMTP.start(@smtp_server, @smtp_port) do |smtp| 131: smtp.send_message(msg, from_address, to_address) 132: end 133: 134: # 135: # 3. Reply to engine 136: 137: reply_to_engine(workitem) 138: end