使用JavaScript生成电子邮件

时间:2014-06-03 21:17:45

标签: javascript jquery html email

我已经对这个问题进行了一整天的研究,但我什么也没做到。有很多脚本可以使用JS创建客户端电子邮件。在我的情况下,我已经成功地将电话号码附加到许多域扩展名。

这是 fiddle ...

的示例结果
4808565309@message.Alltel.com;
 4808565309@txt.att.net;
 4808565309@myboostmobile.com;
 4808565309@sms.mycricket.com;
 4808565309@mymetropcs.com;
 4808565309@messaging.sprintpcs.com;
 4808565309@page.nextel.com;
 4808565309@vtext.com;
 4808565309@tmomail.net;
 4808565309@email.uscc.net;
 4808565309@vmobl.com

现在,我要做的是使用onClick引用将这些电子邮件发送到客户端电子邮件客户端(在我的情况下为Outlook)。

这类似于 mailto:,但将整个textarea类附加到 mailto:是我的目标。

有什么想法?

3 个答案:

答案 0 :(得分:0)

如果您想要多个收件人,那么无法保证安全的方式。请参阅此帖子:http://www.sightspecific.com/~mosh/www_faq/multrec.html

答案 1 :(得分:0)

如果我理解更正,您尝试向用户默认电子邮件客户端发送一封电子邮件,其中包含预先填充的“收件人”字段,其中包含多封电子邮件。

<a href="mailto:email_address">E-mail</a>

如果您尝试在按钮上单击提示电子邮件,则可以尝试使用mailto window.location.href。但是,某些浏览器很可能会拒绝它。

您最好的选择是删除提交按钮并将其更改为标准A标记链接(您可以将其设置为按钮样式)。更改文本字段后,根据文本字段更新mailto链接HREF:

http://jsfiddle.net/N3kJb/10/

答案 2 :(得分:0)

工作小提琴(当点击setVal我设置了一个打开你的mailclient的新功能)

试试这个

http://jsfiddle.net/7QUmU/1/

$(document).ready(function () {
    $('#setVal').on('click', function () {
        // Get the phone number.
        var input = $('.input').val();
        var vals = $('.combine').map(function () {
            var value = $.trim(this.value)
            // Append the phone number before the value.
            return value ? input + value : undefined;
        }).get();
        //Add the phone number to the beginning of the array
        vals.unshift();
        $('#outputAddress').val(vals.join(';\n '))
    });

    $('#setVal').on('click', function () {
        window.open('mailto:'+ $("#input2").val() + '?subject=test&body='+ $("#outputAddress").val()+ '');     
    });

});