Mail Sender Connector
Mail sender connector allows listening to e-mails coming to a specific e-mail address and performing certain actions on these e-mails.
Required Connector Properties
-
Imap Address: An IMAP address is usually in the form of a URL that allows you to connect to your email provider's IMAP server. For example, an IMAP address might be imap.example.com. Here "imap.example.com" is the address of your email provider's IMAP server. This address must be entered in order to access and read your e-mails.
-
Mail Credential: Specifies a name or identifier that denotes the credentials to be used to connect to the IMAP server. This allows the use of pre-defined authentication information.
-
Timeout: The connection timeout in milliseconds.
-
Folder: Specify the folder containing the emails to be read.
-
Selection: Specify which emails to process: All Mails or Only Unread Mails. You can choose whether to process all emails or just the unread ones.
-
Max Messages Per Poll: Specify the maximum number of emails to be retrieved from the email server in one polling step.
-
Delay: Milliseconds before the next poll.
-
Processing Mode: Specify how emails will be processed. The following options are available:
- Archive: Emails are archived in the specified folder after they have been read.
- Archive and Mark as Read: Emails are marked as read and moved to the specified archive folder.
- Delete: Emails are deleted from the mailbox after they have been read.
- Mark as Read: Emails are marked as read.
If the Processing Mode is set to Mark as Read and the polling strategy is set to poll all mail (Selection: All Mails), previously processed mail is reprocessed at each polling interval.
-
Archive Folder: If Processing Mode is set to Archive or Archive and Mark as Read, this field must be filled in. Specify the name of the folder where the email will be moved after it is processed.
-
Add Searchterm: It allows filtering of mails based on search criteria such as subject, body, and from.
- Body: Specifies that the email body will be searched for the specified content. For example, if "MIP" is entered, emails containing this word in the body will be read.
- From: Indicates that e-mails from the specified e-mail address will be searched.
- Subject: Indicates that the email subject will be searched for the specified content. For example, if "MIP" is entered, emails containing this word in the subject will be read.
To access an attachment, you have to use Groovy script. For example;
import org.apache.camel.Exchange
import javax.activation.DataHandler
import org.apache.camel.attachment.AttachmentMessage
import java.nio.charset.StandardCharsets
def Exchange executeMessage(Exchange exchange) {
AttachmentMessage attachmentMessage = exchange.getMessage(AttachmentMessage.class);
Map<String, DataHandler> attachments = attachmentMessage.getAttachments();
if (attachments != null) {
for (String name : attachments.keySet()) {
DataHandler dh = attachments.get(name);
String filename = dh.getName();
if (filename.endsWith(".xml")) {
byte[] data = exchange.getContext().getTypeConverter().convertTo(byte[].class, dh.getInputStream());
String body = new String(data, StandardCharsets.UTF_8);
exchange.getIn().setBody(body);
}
}
}
return exchange
}
This groovy script returns the content as a response if there is a file with ".xml" extension in the attachments of the e-mail.