javascript - 在 javascript 中通过 Lotus Notes 发送邮件

标签 javascript email lotus-notes lotus

我想通过 Internet Explorer 9 通过 IBM Lotus Notes 8.5 发送电子邮件。我已为此任务编写了以下网页。

但是,什么也没有发生。

这是我的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Lotus</title>
    <script language="javascript" type="text/javascript">
   function SendScriptMail() 
{ 
    var mToMail = document.getElementById('txtMailId').value
    var mSub = document.getElementById('txtSubject').value
    var mMsg = document.getElementById('txtContent').value
    var Maildb; 
    var UserName; 
    var MailDbName; 
    var MailDoc; 
    var AttachME; 
    var Session; 
    var EmbedObj; 
    var server; 
    try 
    { 
        // Create the Activex object for NotesSession 
        Session = new ActiveXObject('Notes.NotesSession'); 
        if(Session !=null) 
        { 
            // Get the user name to retrieve database 
            UserName = Session.UserName; 
            // Retrieve database from username 
            MailDbName = UserName.substring(0,1) + UserName.substring(
                UserName.indexOf( " " ,1) + 1 ,UserName.length) + ".nsf" 
            // Get database 
            Maildb = Session.GetDatabase("", MailDbName); 
            // open the database 
            if(Maildb.IsOpen != true) 
            { 
                Maildb.OPENMAIL(); 
            } 
            // Create the mail document 
            MailDoc = Maildb.CREATEDOCUMENT(); 
            // From email id (Username) 
            MailDoc.Form = 'Memo'; 
            // To email id 
            MailDoc.sendto = mToMail; 
            // Subject of the mail 
            MailDoc.Subject = mSub; 
            // Content of the mail 
            MailDoc.Body = mMsg 
                // if you want to save message on send, give true here 
                MailDoc.SAVEMESSAGEONSEND = false; 
            // send the mail (check ensure the internet connection) 
            MailDoc.Send(true); 
            // save the mail in draft (no need of internet connection) 
            MailDoc.Save(false, true); 
            // destroy the objects 
            Maildb = null; 
            MailDoc = null; 
            AttachME = null; 
            EmbedObj = null; 
            Session.Close(); 
            Session = null; 
            alert('Mail sent successfully'); 
        } 
        else 
        { 
            alert('Mail not sent'); 
        } 
    } 
    catch(err) 
    { 
        if(err == '[object Error]') 
        { 
            alert('Error while sending mail,
        Please check Lotus Notes installed in your system'); 
        } 
        else 
        { 
            alert('Error while sending mail'); 
        } 
    } 
}

    </script>
</head>
<body>
    <table width="100%" height="100%">
        <tr>
            <td width="40%" height="130px">
            </td>
            <td>
            </td>
            <td width="40%">
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <table width="100%">
                    <tr>
                        <td style="color: Black; font-size: 10px; font-family: Verdana; text-align: left;"
                            width="100px" valign="top">
                            Mail Id</td>
                        <td>
                            <input id="txtMailId" style="color: #000000; font-size: 10px; font-family: Verdana;
                                height: 11px; text-align: left; top: auto; border: 1px solid #336699; text-decoration: none;
                                width: 176px;" type="text" maxlength="50" /></td>
                    </tr>
                    <tr>
                        <td style="color: Black; font-size: 10px; font-family: Verdana; text-align: left;"
                            valign="top">
                            Subject</td>
                        <td>
                            <input id="txtSubject" style="color: #000000; font-size: 10px; font-family: Verdana;
                                height: 11px; text-align: left; top: auto; border: 1px solid #336699; text-decoration: none;
                                width: 176px;" type="text" maxlength="50" /></td>
                    </tr>
                    <tr>
                        <td style="color: Black; font-size: 10px; font-family: Verdana; text-align: left;
                            height: 79px;" valign="top">
                            Content</td>
                        <td>
                            <textarea id="txtContent" cols="20" style="color: #000000; font-size: 10px; font-family: Verdana;
                                height: 100px; text-align: left; top: auto; border: 1px solid #336699; text-decoration: none;
                                width: 300px;"></textarea></td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td>
                            <input id="btnSend" type="button"  onclick="SendScriptMail();" style="font-family: Verdana; font-size: 11px; text-align: center;
                                top: auto; width: 60px; background-color: #A55129; border: 1px solid #336699;
                                text-decoration: none; font-weight: normal; color: #FFFFFF;" value="Send" />
                            <input id="btnCancel" style="font-family: Verdana; font-size: 11px; text-align: center;
                                top: auto; width: 60px; background-color: #A55129; border: 1px solid #336699;
                                text-decoration: none; font-weight: normal; color: #FFFFFF;" type="button" value="Cancel" onclick="sendEmail();"/></td>
                    </tr>
                </table>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td height="130px">
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
    </table>
</body>
</html>

有什么建议我做错了什么吗?

感谢您的回答!

最佳答案

由于您使用本地 ActiveX 控件,您确定在您使用的计算机上安装了 Notes 客户端(这是正确的 DLL 文件)吗?您是否通过调试器(例如 Firebug)运行 Javascript 来看看会发生什么?

我不会这样做,我会编写一个您从网页调用的服务器端脚本。请参阅下面的代码。然后你只要在服务器上写一个Lotusscript代理来调用即可。它将读取您传递的参数并发送电子邮件。

<script>
$(document).ready(function () {
    // Update content div with dynamic content
    $('#btnSend').click( function() {
        // Get field values
        var mailTo = $('#txtMailId').val();
        var subject = $('#txtSubject').val();
        var content = $('#txtContent').val();
        // Make Ajax call to server, passing address, subject and body as arguments
        $.ajax({
            url: '/database.nsf/SendWebMail?OpenAgent',
            data: {
                mailto: mailTo, 
                subject:subject,
                body:content
            },
            cache: false
        }).done(function(data) {
            $('#returnMessage').html(data);
        }); 
    });
});   
</script>

关于javascript - 在 javascript 中通过 Lotus Notes 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26603070/

相关文章:

java - 为 Lotus Notes 表单动态创建 java 类

javascript - Typescript - 从我的函数中删除样板文件

javascript - 将光标更改为 'move' 上的 'dragstart'

javascript - 我应该如何处理许多嵌套匿名函数中的范围?

php - 任何无需 mail() 即可发送电子邮件的 php 函数

java - com.ibm.jsse2.util.j : Certificate chaining error while accessing a page through https in notes agent

javascript - JQuery 日期选择器 : Disable dates explicitly enabled

c# - HTML 电子邮件 : Must you send an alternate plain text view as well?

php - Swift_TransportException·无法与主机 smtp.sendgrid.net 建立连接 [连接超时 #110]

用于在 Lotus Notes Web 表单中设置字段的 JavaScript