github.com/argoproj/argo-events@v1.9.1/docs/sensors/triggers/email-trigger.md (about)

     1  # Email Trigger
     2  
     3  The Email trigger is used to send a custom email to a desired set of email addresses using an SMTP server. The intended use is for notifications for a build pipeline, but can be used for any notification scenario.
     4  
     5  ## Prerequisite
     6  
     7  1. Deploy the eventbus in the namespace.
     8  
     9  2. Have an SMTP server setup.
    10  
    11  3. Create a kubernetes secret with the SMTP password in your cluster.
    12  
    13          kubectl create secret generic smtp-secret --from-literal=password=$SMTP_PASSWORD
    14  
    15        **Note**: If your SMTP server doesnot require authentication this step can be skipped.
    16  
    17  4. Create a webhook event-source.
    18  
    19          kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml
    20  
    21  5. Set up port-forwarding to expose the http server. We will
    22     use port-forwarding here.
    23  
    24          kubectl port-forward -n argo-events <event-source-pod-name> 12000:12000
    25  
    26  ## Email Trigger
    27  
    28  Lets say we want to send an email to a dynamic recepient using a custom email body template.
    29  
    30  The custom email body template we are going to use is the following:
    31  ```
    32  Hi <name>,
    33    Hello There
    34  
    35  Thanks,
    36  Obi
    37  ``` 
    38  where the name has to be substituted with the receiver name from the event.
    39  
    40  1. Create a sensor with Email trigger.
    41  
    42          kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/email-trigger.yaml
    43  
    44        **Note**: Please update ```email.port```, ```email.host``` and ```email.username``` to that of your SMTP server.
    45          If your SMTP server doesnot require authentication, the ```email.username``` and ```email.smtpPassword``` should be ommitted.
    46  
    47  2. Send a http request to the event-source-pod to fire the Email trigger.
    48  
    49          curl -d '{"name":"Luke", "to":"your@email.com"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example
    50  
    51        **Note**: You can modify the value for key ```"to"``` to send the email to your address.
    52  
    53  2. Alternatively you can skip providing the ```"to"``` in the payload to send an email to static email address provided in the trigger.
    54  
    55          curl -d '{"name":"Luke"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example
    56  
    57        **Note**: You have to remove the parameterization for ```email.to.0``` and add ```email.to``` like so:
    58          ```yaml
    59          email:
    60            ...
    61            to:
    62              - target1@email.com
    63              - target2@email.com
    64            ...
    65          ```
    66  
    67  ## Parameterization
    68  
    69  We can parameterize the to, from, subject and body of the email trigger for dynamic capabilities.
    70  
    71  The email trigger parameters have the following structure,
    72  
    73      - parameters:
    74          - src:
    75              dependencyName: test-dep
    76              dataKey: body.to
    77            dest: email.to.0
    78          - src:
    79              dependencyName: test-dep
    80              dataKey: body.to
    81            dest: email.to.-1
    82          - src:
    83              dependencyName: test-dep
    84              dataKey: body.from
    85            dest: email.from
    86          - src:
    87              dependencyName: test-dep
    88              dataKey: body.subject
    89            dest: email.subject
    90          - src:
    91              dependencyName: test-dep
    92              dataKey: body.emailBody
    93            dest: email.body
    94  
    95  
    96  - ```email.to.index``` can be used to overwite an email address already specified in the trigger at the provided index. (where index is an integer)
    97  - ```email.to.-1``` can be used to append a new email address to the addresses to which an email will be sent.
    98  - ```email.from``` can be used to specify the from address of the email sent.
    99  - ```email.body``` can be used to specify the body of the email which will be sent.
   100  - ```email.subject``` can be used to specify the subject of the email which will be sent.
   101  
   102  To understand more on parameterization, take a look at [this tutorial](https://argoproj.github.io/argo-events/tutorials/02-parameterization/).
   103  
   104  The complete specification of Email trigger is available [here](https://github.com/argoproj/argo-events/blob/master/api/sensor.md#emailtrigger).