advanced-mail-connectivity-using-mime
Version 16.1 by marijn on 2022/05/05 16:17
Send emails
We explained the MIME protocol in the previous [microlearning](advanced-mail-connectivity-whatis-mime.md). In this microlearning, we will expand our knowledge by learning how to send emails with the help of MIME messages via the eMagiz platform.Should you have any questions, please get in touch with academy@emagiz.com.- Last update: January 24th, 2022
- Required reading time: 5 minutes
1. Prerequisites
- Advanced knowledge of the eMagiz platform
- Understanding of the MIME concept
2. Key concepts
- Use the standard components of eMagiz for MIME messages
- Use the standard mail definition provided by eMagiz to structure your MIME message
3. Send emails
We explained the MIME protocol in the previous [microlearning](advanced-mail-connectivity-whatis-mime.md). In this microlearning, we will expand our knowledge by learning how to send emails with the help of MIME messages via the eMagiz platform.eMagiz provides you with a variety of mail-related components to send mail. See below for a snapshot of the current list of components offered by eMagiz with regards to mail. To send a mail, we need at least the support object called "Java mail sender" and the outbound channel adapter called "Mail outbound channel adapter" from the list below.
3.1 Setting up the MIME message
However, before sending a mail with the help of these components, we first need to make sure that the payload of our message is not just a string in JSON or XML form but is a message of the MIME type. For example, you can use a standard component in eMagiz called "XML to MIME message transformer" to achieve this. Note that when transforming your XML to MIME, eMagiz expects a specific structure. For example, the XSD belonging to this structure can be found in the Store under the Store item called: "Send Mail * Java."

3.2 Sending the email
We need to define a mail outbound channel adapter and link it to the Java mail sender to send the email. We also need to consider specific configurations for our Java mail sender, such as providing a username/password combination because the mail server expects an authenticated request. To define the username and password, open the Java mail sender component, navigate to the Advanced tab, define the username and password with the help of properties and define a Java mail property as specified in the help text. The result should look something as follows.

Practice
4. Assignment
Build a flow that can send emails. This assignment can be completed with the help of the (Academy) project that you have created/used in the previous assignment.5. Key takeaways
- Setting up the message in MIME makes it easier to use the Java mail components
- Check out the Store for the relevant store item
- Verify the settings needed to connect to the external mail server before you start building the flow
- Make sure that the transformation to MIME and sending of the mail happens in one flow
6. Suggested Additional Readings
If you are interested in this topic and want more information, please read the release notes and help texts provided by eMagiz. Furthermore, check out the following links:- https://docs.spring.io/spring-integration/docs/2.1.x/reference/html/mail.html#mail-outbound
- https://docs.spring.io/spring-integration/reference/html/mail.html