indexing description: "Origo node to send emails." author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class NODE_MAIL inherit O_NODE_CLIENT redefine register_message_handlers, make end O_MAIL_CONSTANTS create make feature {NONE} -- Initialization make is -- Create. do create smtp_connection_lock.make create smtp_connection.make (smtp_server, local_host_name) Precursor end feature -- Access Peer_description: STRING is "Mail node that allows to send emails." -- Node's peer description name: STRING is "Origo Mail" version: STRING is "$Revision$" feature {NONE} -- Message handlers simple_mail (a_msg: O_MESSAGE) is -- Handle a simple message to send an email. require a_msg_set: a_msg /= Void local l_msg: O_MAIL_MESSAGE do l_msg ?= a_msg check mail_message: l_msg /= Void end send_mail (l_msg.recipient, l_msg.sender, l_msg.subject, l_msg.text) end feature {NONE} -- Implementation register_message_handlers is -- Register message handlers. do Precursor register_message_handler (mail_namespace, mail_simple_type, agent simple_mail) end send_mail (a_recipient, a_sender, a_subject, a_message: STRING) is -- Send a_message to a_recipient. local l_email: EMAIL do -- create message create l_email.make l_email.add_header_entry (l_email.h_from, mail_sender_prefix + a_sender + mail_sender) l_email.add_header_entry (l_email.h_to, a_recipient) l_email.add_header_entry (l_email.h_subject, a_subject) l_email.add_header_entry ("Content-Type", "text/plain; charset=utf-8") l_email.add_header_entry ("Content-Transfer-Encoding", "8bit") l_email.set_message (a_message) -- send message smtp_connection_lock.lock smtp_connection.initiate_protocol smtp_connection.transfer (l_email) smtp_connection.close_protocol smtp_connection_lock.unlock end local_host_name: STRING is -- Host name of the local machine, needed for smtp. local l_host: HOST_ADDRESS once create l_host.make_local Result := l_host.local_host_name end smtp_connection_lock: MUTEX -- Protection for smtp_connection. smtp_connection: SMTP_PROTOCOL -- Connection to the smtp server. smtp_server: STRING is "localhost" -- SMTP server to send mails. mail_sender_prefix: STRING is "[Origo] " -- Sender name prefix mail_sender: STRING -- Sender of the mail. local parser: ORIGO_CONF_PARSER once create parser.make_default Result := "<" + parser.get("email_sender_default") + ">" end end