Added usage of notification_email library.

Added CMS_SETUP.mailer
Updated implementation of email_service to use notification_email library
This commit is contained in:
2015-06-30 15:53:02 +02:00
parent e45dac84c8
commit 8294a47f17
7 changed files with 61 additions and 20 deletions

View File

@@ -21,6 +21,7 @@
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="i18n" location="$ISE_LIBRARY\library\i18n\i18n-safe.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf" readonly="false"/>
<library name="notification_mailer" location="$ISE_LIBRARY\contrib\library\runtime\process\notification_email\notification_email-safe.ecf"/>
<library name="smarty" location="$ISE_LIBRARY\contrib\library\text\template\smarty\smarty-safe.ecf" readonly="false"/>
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>

View File

@@ -22,6 +22,7 @@
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http.ecf"/>
<library name="i18n" location="$ISE_LIBRARY\library\i18n\i18n.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf" readonly="false"/>
<library name="notification_mailer" location="$ISE_LIBRARY\contrib\library\runtime\process\notification_email\notification_email.ecf"/>
<library name="smarty" location="$ISE_LIBRARY\contrib\library\text\template\smarty\smarty.ecf" readonly="false"/>
<library name="text_filter" location="$ISE_LIBRARY\unstable\library\text\text_filter\text_filter.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>

View File

@@ -8,5 +8,7 @@ name=Eiffel CMS
email=your@email.com
theme=bootstrap
[misc]
smtp=localhost
[mailer]
smtp=localhost:25
#sendmail=/usr/bin/sendmail
#output=@stderr

View File

@@ -12,6 +12,7 @@
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms_app_env" location="..\app_env\app_env-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<library name="notification_mailer" location="$ISE_LIBRARY\contrib\library\runtime\process\notification_email\notification_email-safe.ecf"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -7,8 +7,8 @@ class
EMAIL_SERVICE
inherit
SHARED_ERROR
SHARED_LOGGER
create
@@ -31,9 +31,7 @@ feature {NONE} -- Initialization
do
admin_email := parameters.admin_email
-- Get local host name needed in creation of SMTP_PROTOCOL.
create l_address_factory
create smtp_protocol.make (parameters.smtp_server, l_address_factory.create_localhost.host_name)
create {NOTIFICATION_SMTP_MAILER} mailer.make (parameters.smtp_server)
set_successful
end
@@ -43,7 +41,7 @@ feature {NONE} -- Initialization
admin_email: IMMUTABLE_STRING_8
-- Site admin's email.
smtp_protocol: SMTP_PROTOCOL
mailer: NOTIFICATION_MAILER
-- SMTP protocol.
feature -- Basic Operations
@@ -60,38 +58,34 @@ feature -- Basic Operations
send_message (a_from_address, a_to_address: READABLE_STRING_8; a_subjet: READABLE_STRING_GENERAL; a_content: READABLE_STRING_GENERAL)
local
l_email: EMAIL
l_email: NOTIFICATION_EMAIL
utf: UTF_CONVERTER
do
write_debug_log (generator + ".send_message: [from:" + a_from_address + ", to:" + a_to_address + ", subject:" + a_subjet + ", content:" + a_content)
create l_email.make_with_entry (a_from_address, a_to_address)
l_email.set_message (utf.escaped_utf_32_string_to_utf_8_string_8 (a_content))
l_email.add_header_entry ({EMAIL_CONSTANTS}.H_subject, utf.escaped_utf_32_string_to_utf_8_string_8 (a_subjet))
l_email.add_header_entry ("MIME-Version:", "1.0")
l_email.add_header_entry ("Content-Type", "text/html; charset=utf-8")
create l_email.make (a_from_address, a_to_address, utf.escaped_utf_32_string_to_utf_8_string_8 (a_subjet) , utf.escaped_utf_32_string_to_utf_8_string_8 (a_content))
l_email.add_header_line ("MIME-Version:1.0")
l_email.add_header_line ("Content-Type: text/html; charset=utf-8")
send_email (l_email)
end
feature {NONE} -- Implementation
send_email (a_email: EMAIL)
send_email (a_email: NOTIFICATION_EMAIL)
-- Send the email represented by `a_email'.
local
l_retried: BOOLEAN
do
if not l_retried then
write_information_log (generator + ".send_email Process send email.")
smtp_protocol.initiate_protocol
smtp_protocol.transfer (a_email)
smtp_protocol.close_protocol
mailer.process_email (a_email)
write_information_log (generator + ".send_email Email sent.")
if smtp_protocol.error then
if mailer.has_error then
set_last_error ("smtp_protocol reported an error", generator + ".send_email")
else
set_successful
end
else
write_error_log (generator + ".send_email Email not send " + last_error_message )
write_error_log (generator + ".send_email Email not send " + last_error_message)
end
rescue
set_last_error_from_exception (generator + ".send_email")

View File

@@ -147,10 +147,45 @@ feature -- Access
end
build_mailer
local
retried: BOOLEAN
f: FILE
do
to_implement ("Not implemented mailer")
if not retried then
if attached text_item ("mailer.smtp") as l_smtp then
create {NOTIFICATION_SMTP_MAILER} mailer.make (l_smtp)
elseif attached text_item ("mailer.sendmail") as l_sendmail then
create {NOTIFICATION_SENDMAIL_MAILER} mailer.make_with_location (l_sendmail)
elseif attached text_item ("mailer.output") as l_output then
if l_output.is_case_insensitive_equal ("@stderr") then
f := io.error
elseif l_output.is_case_insensitive_equal ("@stdout") then
f := io.output
else
create {PLAIN_TEXT_FILE} f.make_with_name (l_output)
if not f.exists then
f.create_read_write
f.close
end
end
create {NOTIFICATION_STORAGE_MAILER} mailer.make (create {NOTIFICATION_EMAIL_FILE_STORAGE}.make (f))
else
create {NOTIFICATION_STORAGE_MAILER} mailer.make (create {NOTIFICATION_EMAIL_FILE_STORAGE}.make (io.error))
end
else
check valid_mailer: False end
-- FIXME: should we report persistent error message? If yes, see how.
create {NOTIFICATION_NULL_MAILER} mailer
end
rescue
retried := True
retry
end
feature -- Access
mailer: NOTIFICATION_MAILER
feature -- Access: storage
storage_drivers: STRING_TABLE [CMS_STORAGE_BUILDER]

View File

@@ -113,6 +113,13 @@ feature -- Access: Theme
theme_name: READABLE_STRING_32
-- theme name.
feature -- Access
mailer: NOTIFICATION_MAILER
-- Email processor.
deferred
end
feature -- Access: storage
storage_drivers: STRING_TABLE [CMS_STORAGE_BUILDER]