diff --git a/cms-safe.ecf b/cms-safe.ecf index 1fa90e4..eb6ea20 100644 --- a/cms-safe.ecf +++ b/cms-safe.ecf @@ -21,6 +21,7 @@ + diff --git a/cms.ecf b/cms.ecf index 3788249..e587406 100644 --- a/cms.ecf +++ b/cms.ecf @@ -22,6 +22,7 @@ + diff --git a/examples/demo/site/config/cms.ini b/examples/demo/site/config/cms.ini index 822b9e2..c24c612 100644 --- a/examples/demo/site/config/cms.ini +++ b/examples/demo/site/config/cms.ini @@ -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 diff --git a/library/email/email-safe.ecf b/library/email/email-safe.ecf index 54e3618..4cb12d0 100644 --- a/library/email/email-safe.ecf +++ b/library/email/email-safe.ecf @@ -12,6 +12,7 @@ + diff --git a/library/email/email_service.e b/library/email/email_service.e index 833aeb6..07a9ebd 100644 --- a/library/email/email_service.e +++ b/library/email/email_service.e @@ -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") diff --git a/src/configuration/cms_default_setup.e b/src/configuration/cms_default_setup.e index 9f3b42e..1db87cd 100644 --- a/src/configuration/cms_default_setup.e +++ b/src/configuration/cms_default_setup.e @@ -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] diff --git a/src/configuration/cms_setup.e b/src/configuration/cms_setup.e index cfe7584..be9c5ba 100644 --- a/src/configuration/cms_setup.e +++ b/src/configuration/cms_setup.e @@ -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]