-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Events around Zend_Email #1438
Conversation
@rjocoleman I don't understand the point of these pourtions of code:
and
It seems redundant. You're always setting Could you elaborate please? Are we asuming that the |
The answer to this is both yes (if a merchant chooses to) and no (backwards compatible) - to elaborate: Context, the standard email handling is using ZF's In many cases there are hosting level work arounds or modules like As a solution, in this PR the flow is:
This allows observers, using the standard Mage observer pattern, act on the dispatched event e.g. The This should be completely backwards compatible. To further illustrate my point: I have written a proof of concept module that does just this here: https://github.com/icecubenz-open-mage/Icecube_CustomEmailServer This module has a walk through of email in Magento 1/OpenMage in the readme that explains several of the issues: https://github.com/icecubenz-open-mage/Icecube_CustomEmailServer#history In short, this module:
This exact method can be applied to any other mail capable transport e.g. HTTP APIs such as Sendgrid, SES etc (some of these already exist for This PR can be used with our without the linked module, the linked module is simply an example of it in usage. Mail via SMTP (and similar) aren't the only use-cases, the same system of observers in this way also work for adding attachments. A common use case in third party modules is adding PDF attachments with packing slips, invoices etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent contribution with outstanding concept example of usage by @rjocoleman in the module: https://github.com/icecubenz-open-mage/Icecube_CustomEmailServer
Code review accepted.
A +1 from @henryhayes on this one. It's absolutely essential and should have been part of the original Magento 1 core. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not work when developers use directly new Zend_Mail()
.
But this is a good addition (ok, not tested, I using an overload of Zend_Mail
).
Can you use []
instead of array()
and update EVENTS.md?
@rjocoleman would it be possible for you to fix the conflicts and implement the changes requested by @luigifab? |
043e154
to
cb4e66f
Compare
cb4e66f
to
3d5b821
Compare
@fballiano this is done now - thanks! |
Cant merge b/c conflicts :( |
@sreichel it's just |
EVENTS.md moved to docs/ ... With saying "i cant merge" i mean github does not let me merge it until conflicts are resolved. Yep, it needs to be approved again ... :( |
df3ebf1
3d5b821
to
df3ebf1
Compare
@sreichel rebased. thanks |
be1930c
to
70cac1f
Compare
Do not merge it yet. I would like to get one more approval from a maintainer. |
@@ -215,6 +215,12 @@ | |||
| customer_registration_is_allowed | 1.9.4.5 | | |||
| customer_session_init | 1.9.4.5 | | |||
| eav_collection_abstract_load_before | 1.9.4.5 | | |||
| email_queue_send_before | 19.4.18 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to update numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge and update right after, just not to invalidate the reviews
merged and cherry picked to v20 also updated EVENTS.MD with commit 816248f which also has been cherrypicked to v20 |
Current we have several ways of sending email -
Email
,Template
,Newsletter
andQueue
.There are no events around any of these ways of sending email.
There is no way to send to authenticated SMTP servers.
Currently only way to send via SMTP is to rewrite core via third party extensions - there are many extensions that do this (paid, free, open-source etc). These extensions often conflict with each other and are sometimes bundled with packages.
Events are useful for a number of use-cases, for example:
Configuration in
System Configuration -> Advanced -> System -> Mail Sending Settings
includes support forHost
andPort
but these configuration elements have comments saying they're "for Windows servers only". These configuration values are used for PHP'sini_set
method to configure PHP'smail
extension.Zend_Mail
handles mail sending, which supportsTransports
to take care of the actual delivery. However no transport is configured, which defaults to passing to PHP'smail()
function that tries to usesendmail
installed on Linux servers (or SMTP on windows). Havingsendmail
installed and configured on Linux servers is often not possible these days especially in shared hosting environments.This PR:
Zend_Mail
):email_send_before
/email_send_after
email_queue_send_before
/email_queue_send_after
email_template_send_before
/email_template_send_after
newsletter_send_before
/newsletter_send_after
Uses
utf-8
forMage_Core_Model_Email
(utf-8
is used for every other email type but this one seems to have been forgotten).Instantiates a
Zend_Mail_Transport
and passes this to the relevantbefore
event. This transport is used for sending if it is set by the event.This allows developers to hook these events and set transports or manipulate the
Zend_Mail
object without rewriting core.Nothing is done with these events - they're merely dispatched.
Fixed Issues (if relevant)
Zend_Mail
)Manual testing scenarios (*)
before
events https://github.com/icecubenz-open-mage/Icecube_CustomEmailServer (this also includes example code for theafter
events). This extension provides a way to configure a SMTP server then send a test email from each model via system configuration.Questions or comments
I have modelled these events after the popular
SMTP Pro
Extension,Contribution checklist (*)