Chapter 53. GoogleMail
GoogleMail component
Available as of Camel 2.15
Component Description
The Google Mail component provides access to Gmail via the Google Mail Web APIs.
Google Mail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data. Before you can use this component, you will need to create an account and generate OAuth credentials. Credentials comprise of a clientId, clientSecret, and a refreshToken. A handy resource for generating a long-lived refreshToken is the OAuth playground.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-google-mail</artifactId> <version>2.15-SNAPSHOT</version> </dependency>
URI Format
The GoogleMail Component uses the following URI format:
google-mail://endpoint-prefix/endpoint?[options]
Endpoint prefix can be one of:
- attachments
- drafts
- history
- labels
- messages
- threads
- users
GoogleMailComponent
The GoogleMail Component can be configured with the options below. These options can be provided using the component's bean property
configuration
of type org.apache.camel.component.google.mail.GoogleMailConfiguration
.
Option | Type | |
---|---|---|
accessToken | String | OAuth 2 access token. This typically expires after an hour so refreshToken is recommended for long term usage. |
applicationName | String | Google drive application name. Example would be "camel-google-mail/1.0" |
clientId | String | Client ID of the drive application |
clientSecret | String | Client secret of the drive application |
refreshToken |
String
|
OAuth 2 refresh token. Using this, the Google Mail component can obtain a new accessToken whenever the current one expires - a necessity if the application is long-lived. |
scopes | List<String> | Specifies the level of permissions you want a drive application to have to a user account. See https://developers.google.com/gmail/api/auth/scopes for more info. |
Producer Endpoints
Producer endpoints can use endpoint prefixes followed by endpoint names and associated options described next. A shorthand alias can be used for some endpoints. The endpoint URI MUST contain a prefix.
Endpoint options that are not mandatory are denoted by []. When there are no mandatory options for an endpoint, one of the set of [] options MUST be provided. Producer endpoints can also use a special option
inBody
that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message.
Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format
CamelGoogleMail.<option>
. Note that the inBody
option overrides message header, i.e. the endpoint option inBody=option
would override a CamelGoogleMail.option
header.
For more information on the endpoints and options see API documentation at: https://developers.google.com/gmail/api/v1/reference/
1. Endpoint Prefix attachments
The following endpoints can be invoked with the prefix
attachments
as follows:
google-mail://attachments/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
get | id, messageId, userId | com.google.api.services.gmail.model.MessagePartBody |
URI Options for attachments
Name | Type |
---|---|
id | String |
messageId | String |
userId | String |
2. Endpoint Prefix drafts
The following endpoints can be invoked with the prefix
drafts
as follows:
google-mail://drafts/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create | [mediaContent], content, userId |
com.google.api.services.gmail.model.Draft
|
|
delete | id, userId | ||
get | id, userId |
com.google.api.services.gmail.model.Draft
|
|
list | userId |
com.google.api.services.gmail.model.ListDraftsResponse
|
|
send | [mediaContent], content, userId |
com.google.api.services.gmail.model.Message
|
|
update | [mediaContent], content, id, userId |
com.google.api.services.gmail.model.Draft
|
URI Options for drafts
Name | Type |
---|---|
content | com.google.api.services.gmail.model.Draft |
id | String |
mediaContent | com.google.api.client.http.AbstractInputStreamContent |
userId | String |
3. Endpoint Prefix history
The following endpoints can be invoked with the prefix
history
as follows:
google-mail://history/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
list | userId |
com.google.api.services.gmail.model.ListHistoryResponse
|
URI Options for history
Name | Type |
---|---|
userId | String |
4. Endpoint Prefix labels
The following endpoints can be invoked with the prefix
labels
as follows:
google-mail://labels/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
create | content, userId |
com.google.api.services.gmail.model.Label
|
|
delete | id, userId | ||
get | id, userId |
com.google.api.services.gmail.model.Label
|
|
list | userId |
com.google.api.services.gmail.model.ListLabelsResponse
|
|
patch | content, id, userId |
com.google.api.services.gmail.model.Label
|
|
update | content, id, userId |
com.google.api.services.gmail.model.Label
|
URI Options for labels
Name | Type |
---|---|
content | com.google.api.services.gmail.model.Label |
id | String |
userId | String |
5. Endpoint Prefix messages
The following endpoints can be invoked with the prefix
messages
as follows:
google-mail://messages/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
delete | id, userId | ||
get | id, userId |
com.google.api.services.gmail.model.Message
|
|
gmailImport | [mediaContent], content, userId |
com.google.api.services.gmail.model.Message
|
|
insert | [mediaContent], content, userId |
com.google.api.services.gmail.model.Message
|
|
list | userId |
com.google.api.services.gmail.model.ListMessagesResponse
|
|
modify | id, modifyMessageRequest, userId |
com.google.api.services.gmail.model.Message
|
|
send | [mediaContent], content, userId |
com.google.api.services.gmail.model.Message
|
|
trash | id, userId |
|
|
untrash | id, userId |
|
URI Options for messages
Name | Type |
---|---|
content | com.google.api.services.gmail.model.Message |
id | String |
mediaContent | com.google.api.client.http.AbstractInputStreamContent |
modifyMessageRequest | com.google.api.services.gmail.model.ModifyMessageRequest |
userId | String |
6. Endpoint Prefix threads
The following endpoints can be invoked with the prefix
threads
as follows:
google-mail://threads/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
delete | id, userId | ||
get | id, userId |
com.google.api.services.gmail.model.Thread
|
|
list | userId |
com.google.api.services.gmail.model.ListThreadsResponse
|
|
modify | content, id, userId |
com.google.api.services.gmail.model.Thread
|
|
trash | id, userId | ||
untrash | id, userId |
URI Options for threads
Name | Type |
---|---|
content | com.google.api.services.gmail.model.ModifyThreadRequest |
id | String |
userId | String |
7. Endpoint Prefix users
The following endpoints can be invoked with the prefix
users
as follows:
google-mail://users/endpoint?[options]
Endpoint | Shorthand Alias | Options | Result Body Type |
---|---|---|---|
getProfile | userId | com.google.api.services.gmail.model.Profile |
URI Options for users
Name | Type |
---|---|
userId | String |
Consumer Endpoints
Any of the producer endpoints can be used as a consumer endpoint. Consumer endpoints can use Scheduled Poll Consumer Options with a
consumer.
prefix to schedule endpoint invocation. Consumer endpoints that return an array or collection will generate one exchange per element, and their routes will be executed once for each exchange.
Message Headers
Any URI option can be provided in a message header for producer endpoints with a
CamelGoogleMail.
prefix.
Message Body
All result message bodies utilize objects provided by the underlying APIs used by the GoogleMailComponent. Producer endpoints can specify the option name for incoming message body in the
inBody
endpoint URI parameter. For endpoints that return an array or collection, a consumer endpoint will map every element to distinct messages.