-1

i am trying to read a gmail using the routebuilder() of apache camel.

@Component
class ReadEmailRouteBuilder(var stockLocationProperty: 
StockLocationProperty) : RouteBuilder() {

    override fun configure() {
    //TODO
    }
}

This is the start i have to use and i have tried many ways but it never worked, can someone help me?

Alex
  • 53
  • 1
  • 8
  • 1
    duplicate? https://stackoverflow.com/questions/25763655/read-all-mails-from-gmail-inbox-using-apache-camel – i.bondarenko Sep 06 '19 at 14:59
  • I tried it, but it crash on context.getEndpoint with the following error : org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: imaps://imap.gmail.com?closeFolder=false&consumer.delay=60000&delete=false&disconnect=false&password=Ambra321%40&peek=false&unseen=true&username=CamelMail%40gmail.com due to: No component found with scheme: imaps – Alex Sep 06 '19 at 15:29

1 Answers1

1

Dependending on what protocol you are using (IMAP for instance), the answer could look like :

from("imaps://imap.gmail.com?username={{gmail.username}}&password={{gmail.password}}&delete=false&unseen=true&consumer.delay=60000")
    .process(new MailAttachmentProcessor())
    .to("file://gmails");
  • Do you have any error message ? What exactly does not work (compilation, execution, bad data, ...) ? – EfficiencyOverflow Sep 09 '19 at 10:52
  • 1
    This is the error :javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure) – Alex Sep 09 '19 at 13:36
  • OK, so we will start with the obvious : Could you please try to connect with this user and password to the gmail webmail ? I know it's obvious, but we never know until we try. Second, could you please confirm what you put in imaps://imap.gmail.com?username={{gmail.username}} in the place of {{gmail.username}} ? – EfficiencyOverflow Sep 09 '19 at 13:51
  • 1
    I changed the account security settings and it works. Now i can take the Attachments with : exchange.getIn().getAttachments() but i don't know how take the text of the email – Alex Sep 09 '19 at 14:31
  • Mmmm... I would suggest : String body = exchange.getIn().getBody(String.class); – EfficiencyOverflow Sep 09 '19 at 14:40