如何从Chrome扩展程序发送更长的电子邮件? [英] How to send longer emails from a Chrome extension?

查看:140
本文介绍了如何从Chrome扩展程序发送更长的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望制作一个Chrome扩展程序,让用户发送带有自动填写的特定文本的电子邮件。我使用的是 mailto:链接,但无法处理字符串超过1024个字符,并且它不能创建html链接。有没有一种方法可以在电子邮件页面(可能使用本地存储)内填充额外的文本甚至HTML链接?

解决方案

不幸的是,据我所知,没有原生的chrome / javascript API。我做了一些搜索,发现有人正在开发的开源选项,但它非常复杂。他希望别人能够和他一起跳跃并充实自己。



听起来像是在尝试这种方式:



您可以使用& body =标记和网址编码消息,但是长度有限制。这听起来像你已经想出了如何使用chrome打开一个新标签,这样你就可以使用修改后的URL字符串创建更短的电子邮件。我做了一些类似于我第一次铬的暴露。它看起来像这样。

  function sendToUrl(){chrome.tabs.query({active:true,windowId:chrome。 windows.WINDOW_ID_CURRENT},function(tab){
//虽然这似乎正确地生成了URL,但gmail限制了正文文本的长度,因此这不是一个可行的解决方案
//也有没有JavaScript API因此没有希望发送电子邮件

//需要遍历每个标签而不仅仅是第一个标签
var currentTab = tab [0];
var tabInformation = RPATH.getTab(currentTab.id);

var mailUrl =https://mail.google.com/mail/?view=cm&fs=1&tf=1& su = My%20Subject& to =;
//从popup.html获取电子邮件地址
mailUrl + = document.getElementById(to)。value +& body =;

//从popup.html获得formBody
var formBody = document.getElementById(body)。value;
...
//我做了其他一些不相关的东西蚂蚁在这里
...
// Concat最后的邮件地址
mailUrl = mailUrl + formBody;
chrome.extension.sendMessage({mailUrl:mailUrl},function(response){console.log(response.farewell);});
});}

对于更长的电子邮件正文 p>

尽管这只会让你感到一半。我能想到的唯一选择是将选项卡分开并填写电子邮件正文。您可以在页面加载完成后使用追加来修改电子邮件正文。这可能看起来像我下面的内容。注意我选择了iframe元素,然后在其中找到body标签,最后在打开标签后添加一些html。请注意,电子邮件正文只是HTML,所以div,tr,br等标签都应该在创建格式良好的电子邮件中发挥作用。在我之前的例子中,我将表单中的文本从字符串中拉出来。你可以改为使用jquery来克隆你的popup.html页面上的HTML并追加克隆的html。为简单起见,我只将文本放在append中。

  $(iframe#:1t4)。find(body .editable)。append('< p>我的长电子邮件正文< / p>'); 

我想从那里你可以运行一个点击事件,但你也可以把它留给用户。 / p>

I would like to make a Chrome extension that lets users send emails with certain text automatically filled in. I was using a mailto: link, but it cannot handle strings longer than 1024 characters, and it cannot create html links. Is there a way I can fill in additional text and maybe even HTML links, from within the email page (perhaps with local storage)?

解决方案

Unfortunately there is no native chrome/javascript API to my knowledge. I did some searching and found an open source option that someone was working on but it was very skeleton. He was hoping others would jump on with him and flesh it out.

Sounds like you're trying this:

For creating the URL, you can use the &body= tag and url encode the message however there is a limit to the length. It sounds like you already figured out how to open a new tag using chrome so you've been able to create shorter emails using nothing but a modified URL string. I did something similar to that on my first chrome exension. It looked something like this.

function sendToUrl(){ chrome.tabs.query({active:true, windowId: chrome.windows.WINDOW_ID_CURRENT}, function(tab) {
    //while this seems to generate the URL correctly, gmail limits how long the body text can be therefore this is not a viable solution
    //Also there is no javascript API therefore there is no hope of sending an email.

    //Need to loop through each tab and not just the first one
    var currentTab = tab[0];
    var tabInformation = RPATH.getTab(currentTab.id);

        var mailUrl = "https://mail.google.com/mail/?view=cm&fs=1&tf=1&su=My%20Subject&to=";
        // grab the email addresss from popup.html
        mailUrl += document.getElementById("to").value + "&body=";

        // get formBody from popup.html
        var formBody = document.getElementById("body").value;
...
//I did some other stuff that isn't relevant here
...
        //Concat final mailto url
        mailUrl = mailUrl + formBody;
        chrome.extension.sendMessage({mailUrl: mailUrl}, function(response){ console.log(response.farewell);});
});}

For longer email bodies

That only gets you half way though. The only alternative I could think of was to split up the tab open and filling out the email body. You could modify the email body after page load completes using append. That might look something like what I have below. Notice I'm selecting the iframe element, then finding the body tag inside of there, and finally appending some html just after the tag opens. Notice the email body is nothing more then html so div, tr, br, etc tags should all work in creating a well formatted email. In my previous example I pulled the text from the form as a string. You could instead use jquery to clone the html on your popup.html page and append the cloned html. For simplicity's sake, I only put text inside the append.

$("iframe#:1t4").find("body.editable").append('<p>My long email body</p>');

I suppose from there you could run a click event but you could also leave that to the user.

这篇关于如何从Chrome扩展程序发送更长的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆