Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.

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.

OptionType 
accessTokenStringOAuth 2 access token. This typically expires after an hour so refreshToken is recommended for long term usage.
applicationNameStringGoogle drive application name. Example would be "camel-google-mail/1.0"
clientIdStringClient ID of the drive application
clientSecretStringClient 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.
scopesList<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.
p12FileNameStringCamel 2.16:The name of the p12 file which has the private key to use with the Google Service Account.
userStringCamel 2.16.2: The email address of the user the application is trying to impersonate in the service account flow

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]
    
EndpointShorthand AliasOptionsResult Body Type
get id, messageId, userIdcom.google.api.services.gmail.model.MessagePartBody

URI Options for attachments


NameType
idString
messageIdString
userIdString

2. Endpoint Prefix drafts


The following endpoints can be invoked with the prefix drafts as follows:

        google-mail://drafts/endpoint?[options]
    
EndpointShorthand AliasOptionsResult 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


NameType
contentcom.google.api.services.gmail.model.Draft
idString
mediaContentcom.google.api.client.http.AbstractInputStreamContent
userIdString

3. Endpoint Prefix history


The following endpoints can be invoked with the prefix history as follows:

        google-mail://history/endpoint?[options]
    
EndpointShorthand AliasOptionsResult Body Type
list userId
com.google.api.services.gmail.model.ListHistoryResponse

URI Options for history


NameType
userIdString

4. Endpoint Prefix labels


The following endpoints can be invoked with the prefix labels as follows:

        google-mail://labels/endpoint?[options]
    
EndpointShorthand AliasOptionsResult 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


NameType
contentcom.google.api.services.gmail.model.Label
idString
userIdString

5. Endpoint Prefix messages


The following endpoints can be invoked with the prefix messages as follows:

        google-mail://messages/endpoint?[options]
    
EndpointShorthand AliasOptionsResult 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


NameType
contentcom.google.api.services.gmail.model.Message
idString
mediaContentcom.google.api.client.http.AbstractInputStreamContent
modifyMessageRequestcom.google.api.services.gmail.model.ModifyMessageRequest
userIdString

6. Endpoint Prefix threads


The following endpoints can be invoked with the prefix threads as follows:

        google-mail://threads/endpoint?[options]
    
EndpointShorthand AliasOptionsResult 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


NameType
contentcom.google.api.services.gmail.model.ModifyThreadRequest
idString
userIdString

7. Endpoint Prefix users


The following endpoints can be invoked with the prefix users as follows:

        google-mail://users/endpoint?[options]
    
EndpointShorthand AliasOptionsResult Body Type
getProfile userIdcom.google.api.services.gmail.model.Profile

URI Options for users


NameType
userIdString

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.     

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram