0

How I can get sender e-mail by indboxSDK? I tried this:

InboxSDK.load(2, 'sdk_marcin123_e44a6df9c6').then(sdk => {
sdk.Conversations.registerThreadViewHandler(threadView => {

var tytul=threadView.getSubject();
var contact=threadView.getContacts();

//var contact=sdk.User.getFromContact();

const el = document.createElement("div");
    el.innerHTML = '<a href=fire.php?email='+ contact +'>Szukaj klienta</a>';


    threadView.addSidebarContentPanel({
        title: 'Szukaj w EU',
        iconUrl: chrome.runtime.getURL('monkey.png'),
        el
    });
});
});

But I get:

Error logged: TypeError: threadView.getContacts is not a function at sdk

How I can print from e-mail and show at HTML link?

brasofilo
  • 25,496
  • 15
  • 91
  • 179

2 Answers2

4

You can get the sender information with the MessageView handler, it's fairly simple:

sdk.Conversations.registerMessageViewHandler(function(messageView){
 var sender = messageView.getSender();
 // {emailAddress:'some@email.com', name: 'Some Name'}
});

However, as you can see, this is outside the scope of ThreadView, so what I suggest is to have a variable outside both scopes, get the sender information in the MessageView and then use it in ThreadView.

I did something similar in an extension I developed and used setInterval to constantly watch the variable I wanted to use, in your case it should be something like this:

InboxSDK.load(2, 'sdk_marcin123_e44a6df9c6').then(sdk => {
  var sender;

  // Use MessageView to get the sender information
  sdk.Conversations.registerMessageViewHandler(messageView => {
    sender = messageView.getSender();
  });

  sdk.Conversations.registerThreadViewHandler(threadView => {

    var tytul=threadView.getSubject();
    var contact=threadView.getContacts();

    const el = document.createElement("div");

    setInterval(() => {
      if (sender){
        // Do something with the sender information
        el.innerHTML = '<a href=fire.php?email='+ contact +'>Szukaj klienta</a>';

        threadView.addSidebarContentPanel({
          title: 'Szukaj w EU',
          iconUrl: chrome.runtime.getURL('monkey.png'),
          el
        });
      }
    },1000);

  });
});
0

I tried this, this code will work before sending mail from the Gmail.

InboxSDK.load('1', 'sdk_marcin123_e44a6df9c6').then(function (sdk) {
// the SDK has been loaded, now do something with it!
sdk.Compose.registerComposeViewHandler(function (composeView) {
composeView.on('presending', function (event) {
var cv = event.composeView;
cv.insertTextIntoBodyAtCursor(' From Doyenhub Software Solutions LLP.');
var subject = cv.getSubject();
var mail_body = cv.getTextContent();
var toAddress = cv.getToRecipients();
var ccAddress = cv.getCcRecipients();
var bccAddress = cv.getBccRecipients();
//This variables will give the email data from the compose mail box
});
});

Hope this will helps you.

Sunil Dora
  • 1,407
  • 1
  • 13
  • 26