使用Javascript在默认应用程序中打开新电子邮件

时间:2015-06-16 04:42:24

标签: javascript php email owncloud

我很感激这方面的任何帮助。我是新手。 我正在自定义一个OwnCloud设置,它有一个很好的设置来共享应用程序通过内部系统创建的链接,但我需要它在默认的电子邮件应用程序(如Outlook)中打开一个电子邮件,并在电子邮件中有链接。我希望自定义已存在的代码。有一个share.js文件和一个share.php文件。以下是share.js的摘录:

选项1 - 操作包含我希望包含在电子邮件中的链接的表单区域:

        html += '<label for="linkText" class="hidden-visually">'+t('core', 'Link')+'</label>';
        html += '<input id="linkText" type="text" readonly="readonly" />';
        html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>';
        html += '<div id="linkPass">';
        html += '<label for="linkPassText" class="hidden-visually">'+t('core', 'Password')+'</label>';
        html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Choose a password for the public link')+'" />';
        html += '<span class="icon-loading-small hidden"></span>';
        html += '</div>';

我尝试过多种方式改变它,例如:

        html += '<form method="POST" action="mailto:kyle.s@pandplandservice.com?body=Link">';
        html += '<label for="linkText" class="hidden-visually">'+t('core', 'Link')+'</label>';
        html += '<input id="linkText" type="text" readonly="readonly" />';
        html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>';
        html += '<div id="linkPass">';
        html += '<label for="linkPassText" class="hidden-visually">'+t('core', 'Password')+'</label>';
        html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Choose a password for the public link')+'" />';
        html += '<span class="icon-loading-small hidden"></span>';
        html += '<br />';
        html += '<input type="submit" value="Send Link" />';
        html += '</form>';
        html += '</div>';

然后我收到一封要打开的电子邮件,但它不包含该链接。

选项2 - 这是从应用程序发送消息的表单的一部分,但是我需要它来打开一个电子邮件消息,其中包含它将在内部发送的相同内容(或至少链接):

                            html += '<form id="emailPrivateLink">';
            html += '<input id="email" style="display:none; width:62%;" value="" placeholder="'+t('core', 'Email link to person')+'" type="text" />';
            html += '<input id="emailButton" style="display:none;" type="submit" value="Send Email" />';

该表单引用的js文件部分:

$(document).on('submit', '#dropdown #emailPrivateLink', function(event) {
    event.preventDefault();
    var link = $('#linkText').val();
    var itemType = $('#dropdown').data('item-type');
    var itemSource = $('#dropdown').data('item-source');
    var file = $('tr').filterAttr('data-id', String(itemSource)).data('file');
    var email = $('email').val();
    var expirationDate = '';
    if ( $('#expirationCheckbox').is(':checked') === true ) {
        expirationDate = $( "#expirationDate" ).val();
    }
    if (email !='') {
        $('#email').prop('disabled', true);
        $('#email').val(t('core', 'Sending ...'));
        $('#emailButton').prop('disabled', true);
        $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file, expiration: expirationDate},
            function(result) {
                $('#email').prop('disabled', false);
                $('#emailButton').prop('disabled', false);
            if (result && result.status == 'success') {
                $('#email').css('font-weight', 'bold');
                $('#email').animate({ fontWeight: 'normal' }, 2000, function() {
                    $(this).val('');
                }).val(t('core','Email Sent'));
            } else {
                OC.dialogs.alert(result.data.message, t('core', 'Error while sharing'));

非常感谢任何和所有帮助。

1 个答案:

答案 0 :(得分:4)

function sendMail() {
    var link = "mailto:me@example.com"
             + "?cc=myCCaddress@example.com"
             + "&subject=" + escape("This is my subject")
             + "&body=" + escape("This is content of email")
    ;

    window.location.href = link;
}

Sending emails with Javascript

相关问题