Sending an email in iOS via the Gmail API is a breeze

Here we'll show you how to use our iOS SDK to send an email via the Gmail API.

Get Set Up

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

2Make sure you've downloaded the Temboo iOS SDK.

3You'll also need a Gmail account, which you can create here. To authenticate with Google, you'll want to enable 2-Step Verification and generate an App Password for Temboo.

4Sign 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.

5Scroll down to the "Signing in" box.

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

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

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

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

10Click "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.

11 Go to the Google > Gmail > SendEmail Choreo in our Library.

12Fill in your Gmail username (full email address) and App-specific password, then hit the Save Profile button to save a Profile for your Gmail account. Now you can reuse your Gmail authentication details on any of our Gmail Choreos and it will also make your iOS code simpler and more secure.

Test the Choreo

13Now let's test the Google > Gmail > SendEmail Choreo directly from our website. Select iOS from the drop down menu at the top of the page. Insert your new Profile and fill in the rest of the required inputs.

14 Click Generate Code and you'll see the value "true" for the Success output in the Output section. Assuming you emailed yourself, you can go to your inbox and see the email appear!

Create Your iOS Program

15Create a new OS X > Application > Command Line project in Xcode, importing the core folder of Temboo iOS SDK along with the TMBGoogle.h and TMBGoogle.m files as described in our iOS getting started tutorial.

16To send an email from your iOS code, copy the generated iOS code from your browser and paste it into your project's main.m file between the Foundation.h import statement and the main method. Make sure that you're using the Profile you created earlier and that you're sending the email to the address you want to send it to.

17Finally, make sure to update your main method to run the Choreo. Your code should look something like this (the main method is at the end):

#import <Foundation/Foundation.h>
#import "TMBGoogle.h"
#import "TMBChoreography.h"
#import "TMBTembooSession.h"

@interface SendEmail : NSObject <TMBChoreographyDelegate>

@implementation SendEmail

-(void)runSendEmailChoreo {
	// Instantiate the Choreo, using a previously instantiated TembooSession object, eg:
	TMBTembooSession *session = [[TMBTembooSession alloc] initWithAccount:@"ACCOUNT_NAME" appKeyName:@"APP_NAME" andAppKeyValue:@"APP_KEY"];
	// Create the choreo object using your Temboo session
	TMBGoogle_Gmail_SendEmail *sendEmailChoreo = [[TMBGoogle_Gmail_SendEmail alloc] initWithSession:session];	
	// Get Inputs object for the choreo
	TMBGoogle_Gmail_SendEmail_Inputs *sendEmailInputs = [sendEmailChoreo newInputSet];

	// Set credential to use for execution
	[sendEmailInputs setCredential:@"YOUR_GMAIL_TEMBOO_PROFILE"];

	// Set inputs
	[sendEmailInputs setMessageBody:@"You just sent this email via Temboo's iOS SDK - awesome!"];
	[sendEmailInputs setSubject:@"Hello World!"];
	[sendEmailInputs setFromAddress:@""];
	[sendEmailInputs setToAddress:@""];

	// Execute choreo specifying this class as the choreo delegate
	[sendEmailChoreo executeWithInputs:sendEmailInputs delegate:self];

// TMBChoreographyDelegate method implementation - handle choreo errors
-(void)choreographyDidFailWithError:(NSError*)error {
	// Log error to the console
	NSLog(@"Error - %@", error);

// TMBChoreographyDelegate method implementation - choreo executed successfully
-(void)choreographyDidFinishExecuting:(TMBGoogle_Gmail_SendEmail_ResultSet*)result {
	// Log results to the console
	NSLog(@"%@", [result getSuccess]);


int main(int argc, const char * argv[]) {
    @autoreleasepool {
        SendEmail *tutorial = [[SendEmail alloc] init];
        [tutorial runSendEmailChoreo];
        [[NSRunLoop currentRunLoop] run];
    return 0;

18Run the code and check your inbox - your email should be waiting.

What next?

We're all finished! Now your iOS application is sending email via your Gmail account. Why not check out the rest of the 2000+ Choreos in our Library and think about how you could extend this example by combining it with something else.

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, and we'll answer your questions.