Sending Emails
It is possible to send Emails via a Custom Step by using the IoT Insights Messaging REST API. This API encapsulates
the Mailjet API. But only the Mailjet Send V3.1 API is available via the Messaging REST API. In the following it will be referenced as Messaging REST API.
The java and python examples illustrate how this Messaging REST API should be used in order to send Email using
carbon copy
blind carbon copy
attachments
HTML
The code examples provided for Java or Python are explained in detail in the following . They can be customized according to your needs.
Java examples
|
|
|
src/main/java/com/example/myfirstcustomstep/ SendEmail.java |
This is the java class providing an example to send emails. The name of the class can be changed according to your needs in the executable-manifest.yaml file. |
YES |
executable-manifest.yaml |
In the manifest, you configure which java class is used for the startup. |
YES |
*.jar |
Unlike the Python example, all required dependencies are downloaded locally. When building the artifact with our maven plugin, the dependencies specified in the pom.xml file are automatically added to the jar. |
YES |
|
|
|
src/main/java/com/example/myfirstcustomstep/ SendHtmlEmail.java |
This is the java class providing an example to send HTML emails. The name of the class can be changed according to your needs in the executable-manifest.yaml file. |
YES |
executable-manifest.yaml |
In the manifest, you configure which java class is used for the startup. |
YES |
*.jar |
Unlike the Python example, all required dependencies are downloaded locally. When building the artifact with our maven plugin, the dependencies specified in the pom.xml file are automatically added to the jar. |
YES |
Python examples
|
|
|
executable-manifest.yaml |
In the manifest, you configure which script file is used for the startup. |
YES |
example-snippets/send_email.py |
This is the Python script serves as example for sending emails. In order to use this example in the custom step, move it to the src folder and adapt the python.file property in the executable-manifest.yaml file accordingly. |
YES |
requirements.txt |
Add dependencies to this file according to the imported modules of send_email.py. All packages on the pypi.org website are available to list them here, as long as they run on a Linux Ubuntu 18.04 operating system. |
YES |
|
|
|
executable-manifest.yaml |
In the manifest, you configure which script file is used for the startup. |
YES |
example-snippets/send_html_email.py |
This is the Python script serves as example for sending HTML emails. In order to use this example in the custom step, move it to the src folder and adapt the python.file property in the executable-manifest.yaml file accordingly. |
YES |
requirements.txt |
Add dependencies to this file according to the imported modules of send_html_email.py. All packages on the pypi.org website are available to list them here, as long as they run on a Linux Ubuntu 18.04 operating system. |
YES |
In the examples a project specific URL suffix must be adapted. Replace <project-id> with your concrete project ID.
/messaging-proxy/v1/messaging/<project-id>/sendEmail
Environment Variables
Following environment variables, which are provided by the Processing Pipeline App automatically, must be referenced in the custom code:
EMAIL_API_RESTURL: The base URL of the Messaging REST API.
EMAIL_API_USERNAME: The username for the Messaging REST API.
EMAIL_API_PASSWORD: The password for the Messaging REST API.
EMAIL_FROM: The email address of the sender. It is not allowed to change the From EMail address, otherwise problems will occur during the sending process.
HTML Email Templates
If you want to use your email templates you can download them from
Admin -> White labeling -> Email Templates.
Check the SendHtmlEmail.class or send_html_email.py how you can use such templates within your custom
step.
Payload for Sending Emails
A HTTP POST request for sending emails via the Messaging REST API should be a JSON document and compliant to the Email Mailjet REST API. Following structure serves as example:
{
"Messages"
: [
{
"From"
: {
"Email"
:
"john.doe@example.com"
,
"Name"
:
"John Doe"
},
"To"
: [
{
"Email"
:
"jane.doe@example.com"
,
"Name"
:
"Jane Doe"
}
],
"Cc"
: [
{
"Email"
:
"jack.doe@example.com"
,
"Name"
:
"Jack Doe"
},
{
"Email"
:
"jill.doe@example.com"
,
"Name"
:
"Jill Doe"
}
],
"Bcc"
: [
{
"Email"
:
"james.doe@example.com"
,
"Name"
:
"James Doe"
},
{
"Email"
:
"julia.doe@example.com"
,
"Name"
:
"Julia Doe"
}
],
"Subject"
:
"Test Email"
,
"TextPart"
:
"Hello, this is a test email."
,
"Attachments"
: [
{
"ContentType"
:
"text/plain"
,
"Filename"
:
"test.txt"
,
"Base64Content"
:
"SGVsbG8gd29ybGQh"
}
]
}
]
}