1

I am creating chrome extension for gmail, I want send a mail when user click a button created by my extension. I am using inboxsdk for creating extension.

I am creating button using following code

InboxSDK.load('1', '**************').then(function(sdk){
    // the SDK has been loaded, now do something with it!
    sdk.Compose.registerComposeViewHandler(function(composeView){

        // a compose view has come into existence, do something with it!
        composeView.addButton({
            title: "button-title-goes",
            iconUrl: 'https://image.ibb.co/mXS2ZU/images.png',
            onClick: function(event) {
                console.log( event );
                event.composeView.insertHTMLIntoBodyAtCursor('<img src="https://image.ibb.co/mXS2ZU/images.png" alt="Smiley face" height="1" width="1">');
            },
        });

    });
});

I want to send mail when user click on this button.

Anudeep GI
  • 931
  • 3
  • 14
  • 45
  • Have you checked this [SO post](https://stackoverflow.com/questions/42468422/how-do-we-add-new-button-to-gmail-compose-bar-in-chrome-extension-is-it-through)? – Jessica Rodriguez Oct 16 '18 at 07:25
  • Yes, but no use from that SO post. – Anudeep GI Oct 20 '18 at 15:00
  • 1
    You can try `send(sendOptions)` method of the `ComposeView` class of `InboxSDK`. The doc describes the above method as `Simulates clicking the compose's send button.`. Here is the [link](https://www.inboxsdk.com/docs/#ComposeView) to it. – Pallavi Goyal Oct 23 '18 at 12:36

1 Answers1

3

Use the compose views send() function like follows.

sdk.Compose.registerComposeViewHandler(function(composeView){
    composeView.addButton({
        title: "button-title-goes",
        iconUrl: 'https://image.ibb.co/mXS2ZU/images.png',
        onClick: function(event) {
            console.log( event );
            event.composeView.insertHTMLIntoBodyAtCursor('<img src="https://image.ibb.co/mXS2ZU/images.png" alt="Smiley face" height="1" width="1">');
            composeView.send();
        },
    });

});

You can even hand over an optional configuration object which allows you to send and archive. InboxSDK - ComposeView