How to send an email using Gmail API and Java

The Gmail API public docs have a guide on sending email and it even has java sample code:

https://developers.google.com/gmail/api/guides/sending

Your code above doesn't seem that far off though. I'd first make sure you got Oauth2 working right by doing something simple like labels.list() and if that works then move on to something more complicated like sending an email. (You have the right idea constructing, turning into a string, base64url encoding and then sending it though.) What is the exact problem you're getting whist trying to send it with the Gmail API? Got some error output or missing something in your code?


If you are using Java Mail API in your openshift application,

Then adding any new libraries in the application, you have to add its maven-configuration in the pom.xml file. Or in other words, you have to add dependency in the pom.xml file.

this is the dependency for mail-1.4.7 Just add this code in the pom.xml file

<dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>

Similarly, for any other integrations, not forget to add dependencies. You can search in google : "maven dependency for ________"