Send an email in Processing


Here we'll show you how to send an email from Gmail in Processing.

Get Set up

1 Log in to Temboo. If you don't already have an account, you can register for free.

2Make sure you have a Gmail account. If you don't have one already, create one. To authenticate with Google, you'll want to enable 2-Step Verification and generate an App Password for Temboo.

3Sign in to your Google Account settings page by clicking on your name or picture in the upper right corner of the screen and then clicking Account.

4Scroll down to the "Signing in" box.

5Click 2-Step Verification. This will bring you to the 2-Step Verification settings page.

6You will then see a step-by-step guide which will guide you through the setup process.

7After you've enabled 2-Step Verification, you'll be prompted to create an App Password.

8In the Select app dropdown menu, choose "Other", and give this app a name (e.g., TembooApp).

9Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo.

Note: If you wish to authenticate with OAuth credentials, you should use the Google > Gmailv2 Choreos.

10 Store your Google account details in a Temboo Profile. Go to the Google > Gmail > SendEmail Choreo in our Library. Enter the Google Username and App-Specific Password you're using for the sketch in the appropriate inputs. Click on the Save Profile button, name your Profile, and save.

Now you can reuse these Google authentication details on any Google Choreo in our Library. It will make your code a lot simpler and protect your password from appearing in your sketch.

Test the Choreo

11 Now we'll test the Google > Gmail > SendEmail Choreo directly from our website.

12 If they aren't already there, you should insert your Profile values, then fill in the rest of the required inputs, as shown in the screenshot below. It's best to send an email to yourself first, so that you can easily check that it worked.

An example of a correctly filled in set of Choreo inputs

13 Click Generate Code to test the Choreo from our website. If there are no errors, you'll see "true" in the Output section. And if you check the email account you put as your ToAddress, you'll see your email arrive

Run it in Processing

14 To try out the code yourself, you can copy the generated Code from the Choreo page or from the code box below, paste it into your Processing sketch, and run it there. The same email should appear in your inbox.

If you're copying the code below, remember to substitute in your Temboo account details and the name of your Temboo Google Profile.

import com.temboo.core.*;
import com.temboo.Library.Google.Gmail.*;

// Create a session using your Temboo account application details
TembooSession session = new TembooSession("ACCOUNT_NAME", "APP_NAME", "APP_KEY");

// The name of your Temboo Google Profile 
String googleProfile = "myProfileName";

// Declare the strings for your email
String fromAddress = "Project Name <from.address@gmail.com>";
String toAddress = "to.address@gmail.com";
String subject = "An email from Temboo";
String messageBody = "You just sent an email with Temboo and Processing. (Write me something new next time!)";

void setup() {
  // Run the SendEmail Choreo function
  runSendEmailChoreo();
}

void runSendEmailChoreo() {
  // Create the Choreo object using your Temboo session
  SendEmail sendEmailChoreo = new SendEmail(session);

  // Set Profile
  sendEmailChoreo.setCredential(googleProfile);

  // Set inputs
  sendEmailChoreo.setMessageBody(messageBody);
  sendEmailChoreo.setSubject(subject);
  sendEmailChoreo.setFromAddress(fromAddress);
  sendEmailChoreo.setToAddress(toAddress);

  // Run the Choreo and store the results
  SendEmailResultSet sendEmailResults = sendEmailChoreo.run();
  
  // Print results
  println(sendEmailResults.getSuccess());

}

What next?

We're all finished! This sketch contains a not so exciting email message, but any value or string you generate in Processing could be sent. Try hooking this Choreo into anywhere you want to send an email from Processing. And check out our Library for some more ideas.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.


Back