Search code examples
javascriptgoogle-chromegoogle-chrome-extensionemail-client

'Body' empty when opening default email client in chrome extension


I am creating a chrome extension wherein the some content should be sent as email on a button click. I am trying to invoke the default email client using the below code :

function sendlist(tabs) 
{

  var contents = '';
  for (var i = 0; i < tabs.length; i++) 
  {
        if(!tabs[i].pinned)
      contents += tabs[i].url + '\n\n\n';
  }
    var link = "mailto:?&body="+contents;
    alert(link);
    chrome.tabs.create({url: link});

}

The content of variable 'link' needs to be send as Body of the email. strong text**If i use 'chrome.tabs.create({url:link}); then it will invoke the default email client but the body part will be empty.

Is there any way to open the default email client say 'Outlook' and get the values of 'link' in body part of that email?


Solution

  • The problem occurred due to wrong formatting of the mail headers. The correct syntax would be :

    var link = "mailto:?body="+escape(contents);
    

    Using the escape() function formatted the required content properly. Also, I removed the & before the body header.