User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:devel:sendemailservice [2019/06/22 14:18]
joebordes
en:devel:sendemailservice [2019/08/30 12:58] (current)
Line 3: Line 3:
 coreBOS has an abstraction layer for sending emails, instead of always sending with phpmailer, now we can define a class to send as we want. This allows us to integrate with other email delivery systems such as sendgrid or mailchimp without having to modify the code of the application. coreBOS has an abstraction layer for sending emails, instead of always sending with phpmailer, now we can define a class to send as we want. This allows us to integrate with other email delivery systems such as sendgrid or mailchimp without having to modify the code of the application.
  
-In [[http://​blog.corebos.org/en/​blog/​emailapisendgrid|this blog post]] you can get a general idea of the implications and next we will see how to implement a class of sending emails by studying the sendgrid integration code+In [[http://​blog.corebos.org/​blog/​emailapisendgrid|this blog post]] you can get a general idea of the implications and next we will see how to implement a class of sending emails by studying the sendgrid integration code
  
 The steps to implement an email sending system are The steps to implement an email sending system are
  
-   * implement a class with at least 3 static methods +  ​* implement a class with at least 3 static methods 
-   * implement an event handler that returns the path and the name of the class +  * implement an event handler that returns the path and the name of the class 
-   * register the handler+  * register the handler
  
 the class must implement these three methods the class must implement these three methods
Line 17: Line 17:
   * public static function sendEMail( $to_email,​$from_name,​$from_email,​$subject,​$contents,​$cc,​$bcc,​$attachment,​$emailid,​$logo,​$replyto,​$qrScan)   * public static function sendEMail( $to_email,​$from_name,​$from_email,​$subject,​$contents,​$cc,​$bcc,​$attachment,​$emailid,​$logo,​$replyto,​$qrScan)
  
-the **useEmailHook** method returns a true or false value depending on whether the service is active or not. This allows us to implement a simple way to activate and deactivate the service. ​if it returns false we will use the default ​shipping ​system+the **useEmailHook** method returns a true or false value depending on whether the service is active or not. This allows us to implement a simple way to activate and deactivate the service. ​If it returns false we will use the default ​email delivery ​system
  
-the ** emailServerCheck ** method returns a true or false value depending on whether the service is configured or not. if it returns false we will use the default ​shipping ​system+The **emailServerCheck** method returns a true or false value depending on whether the service is configured or not. If it returns false we will use the default ​email delivery ​system
  
-the method ** sendEMail ** is the one that actually does the work of sending the email. ​it receives all the information it needs to do that. you can [[http://​blog.corebos.org/en/​blog/​SendEmail|read a little about the parameters in this blog post]]. ​this method must return 1 on ok, any other value is error+The method **sendEMail** is the one that actually does the work of sending the email. ​It receives all the information it needs to do that. You can [[http://​blog.corebos.org/​blog/​SendEmail|read a little about the parameters in this blog post]]. ​This method must return 1 on ok, any other value is error
  
 +Let's talk a little bit about these methods in our sendgrid implementation. These are the methods [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L128|useEmailHook]] and [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L306|emailServerCheck]]
  
- +we can see that the functionality ​of both is the same and is based simply ​on whether ​the client has activated ​the service or not. We do not check the configuration of the account in SendGrid.
-el método **useEmailHook** devuelve un valor verdadero o falso según este activo o no el servicio. esto nos permite implementar una manera sencilla de activar y desactivar el servicio. si devuelve falso utilizaremos el sistema de envío por defecto  +
- +
-el método **emailServerCheck** devuelve un valor verdadero o falso según este configurado o no el servicio. si devuelve falso utilizaremos el sistema de envío por defecto +
- +
-el método **sendEMail** is the one that actually does the work of sending the email. it receives all the information it needs to do that. you can [[http://​blog.corebos.org/​en/​blog/​SendEmail|read a little about the parameters in this blog post]]. this method must return 1 on ok, any other value is error +
- +
-vamos a comentar un poco estos métodos en nuestra implementación de sendgrid +
- +
-estos son los métodos [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L128|useEmailHook]] y [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L306|emailServerCheck]] +
- +
-podemos ver que la funcionalidad siempre está disponible ya que es la funcionalidad por defecto y que devolveremos verdadero o falso según se haya configurado el servicio o no. +
- +
-[[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L132|aquí puedes ver el método sendEMail]] +
- +
-Ahora implementamos el event handler que devuelve el nombre y ubicación de la clase +
- +
- +
-let's talk a little bit about these methods in our sendgrid implementation +
- +
-these are the methods [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L128|useEmailHook]] and [[https://​github.com/​tsolucio/​ corebos / blob / master / include / integrations / sendgrid / sendgrid.php # L306 | emailServerCheck]] +
- +
-we can see that the functionality ​is always available since it is the default functionality ​and that we will return true or false depending ​on whether the service ​has been configured ​or not.+
  
 [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L132|here you can see the sendEMail method]] [[https://​github.com/​tsolucio/​corebos/​blob/​master/​include/​integrations/​sendgrid/​sendgrid.php#​L132|here you can see the sendEMail method]]
  
 Now we implement the event handler that returns the name and location of the class Now we implement the event handler that returns the name and location of the class
- 
  
 <code PHP> <code PHP>
Line 76: Line 54:
 </​code>​ </​code>​
  
-Con esto solo tenemos que implementar una manera sencilla para que el administrador pueda dar de alta sus datosNosotros lo hemos hecho en <​code>​module=Utilities&​action=index</​code>​+With this, we just have to implement a simple way for the administrator to register their dataWe have done it in <​code>​module=Utilities&​action=index</​code>​
  
 {{:​en:​devel:​emailapi:​sendgridconfiguration.png|sendgrid configuration}} {{:​en:​devel:​emailapi:​sendgridconfiguration.png|sendgrid configuration}}
  
-En el caso particular ​de sendgrid, ​además implementamos una captura de eventos para marcar los distintos estados del mensaje así como lanzar los flujos de trabajoEsto lo construimos utilizando el servicio de notificaciones de coreBOS (notifications.php)+In the particular ​case of sendgrid, ​we also implement a capture of events to mark the different states of the message as well as launch the workflowsWe built this using the notifications service of coreBOS (notifications.php)
  
- 
-With this we just have to implement a simple way for the administrator to register their data. We have done it in <​code>​ module = Utilities & action = index </ code> 
- 
-{{: en: devel: emailapi: sendgridconfiguration.png | sendgrid configuration}} 
- 
-In the particular case of sendgrid, we also implement a capture of events to mark the different states of the message as well as launch the workflows. We built this using the notifications service of coreBOS (notifications.php)