现在的位置: 首页 > 综合 > 正文

Lotus Notes email via vbscript

2013年04月05日 ⁄ 综合 ⁄ 共 13251字 ⁄ 字号 评论关闭

My company just migrated to Lotus Notes emailing system and I need to convert all our current web applications to communicate using Lotus Notes. The application that I currently needs to change is our Online Leave Application which was written in vbscript. I have created a new sendmail function to send mail via lotus notes in the web page, however I am getting error message that I am unable to createobject("Notes.NotesSession").
 
I saw your posting that you are able to load Lotus Notes email to the webpages, hence I strongly believe you are able to communicate using the Lotus Notes COM objects using vbscript. I hope that you can help me on this matter in order to convert my web applications to send email via Lotus Notes.
 
Below is the source of one of my webpage:
 
<%@ LANGUAGE="VBSCRIPT"  %>
<!--#include virtual="/common/login_leave.asp"-->
 
 
<HTML>
 
<HEAD>
<object runat="Server" id="nSession" classid="clsid:29131539-2EED-1069-BF5D-00DD011186B7"></object>
<title>Save Leave</title>
<link href="Intranet.css" rel="stylesheet" type="text/css">
 
</HEAD>
 
<body bgcolor="#FFDFAA" text="#000000" link="#804040" vlink="#008080" alink="#004080">
<!--#include virtual="/common/main_header.asp"-->
<%
dim lv, rs, empl, msg, rsTypes
dim strEmailMsg, rsLastMinute, dtToday
dtToday= Date()
startdate = CDATE(request("LeaveStartDate") )
enddate = cdate(Request("LeaveEndDate") )
if datediff("d",startdate,enddate) < 0 then
                Response.Write("<BR><BR><CENTER>The End Date can not be earlier then the Start Date. Please return to the previous screen to change your dates.</CENTER>")
                Response.End
end if
reason = request("reason")
dateapplied = "#" & date() & "#"
leavetype = request("leavetype")
 
if not isempty(Request.form) and session("leaveSaved") = 0 then
                set lv = new Leave              
                'check the dates before saving, exit if invalid
                if lv.calculateleavedays(startdate,request("startperiod"),enddate,request("endperiod"),session("employeenum")) = -1 then
                                Response.Write("End date is incorrect, please go back and change.")
                                Response.end      
                end if
 
                lv.EmployeeID = session("employeenum")
                lv.StartDate = request("LeaveStartDate")
                lv.EndDate  = request("LeaveEndDate")
                lv.StartPeriod = request("startperiod")
                lv.EndPeriod = request("endperiod")              
                lv.reason = reason
                lv.leavetype = leavetype
                'set to prevent saving the record more than once when user refreshes the page
                session("leaveSaved") = lv.AddNew()           
                rs = getRecordSet(SCONNECTION, "SELECT * from Leave WHERE leaveid = " & session("leaveSaved") )
                set rsTypes = getRecordSet(SCONNECTION,"Select * from leavetype")
                set empl = new Employee
                empl.GetEmployeeInfo(session("employeenum"))
                set Supervisor = new Employee
                Supervisor.GetEmployeeInfo(empl.Supervisor)
                set HOD = new Employee
                HOD.getEmployeeInfo(empl.HOD)
                'send email to supervisor
                user = empl.Supervisor
 
                str = "<HTML><BODY>Dear " & Supervisor.name & ":<BR><BR>" & empl.name & _
                                                " has applied to take leave." &_
                "<form name='frmApprove' method='GET' action='" & conURL & "leave_system/approveleave.asp'>" & _
                "<table  border = '1' align = 'center'>" & _
                "              <tr><td>Leave ID:</td><td>" & rs("leaveid") & "</td></tr>" & _
                "              <TR><td>Date of Application</td><td>" & rs("dateapplied") &  "</td></TR>" & _
                "              <tr><td>Name</td><td>" & empl.name &  "</td></tr>" & _
                "              <tr><td>Employee Number</td><td>" & rs("employeenum") &  "</td></tr>" & _
                "              <tr><td>Department</td><td>" & empl.department &  "</td></tr>" & _
                "              <tr><td>From</td><td>" & rs("startdate") &" (" & rs("startperiod") & ")" &  "</td><tr><td>To</td><td>" & rs("enddate") & " (" & rs("endperiod") & ")"  &  "</td></tr>" & _
                "              <tr><td>Total Working Days Applied</td><td>" & rs("totaldays") &  "</td></tr>" & _
                "              <tr><td>Reason</td><td>" & rs("reason") &  "</td></tr>" & _
                "              <tr><td>Type of Leave</td><td>" & _
                "                              <SELECT name='type'>"                    
                                                                Do while not rsTypes.EOF
                                                                                if strComp(rsTypes("leavetype"),rs("leavetype"),1) then
                                                                                                  str = str & "<option value=" & rsTypes("leavetype") &  " >" & rsTypes("leavetype") &  "</option>"
                                                                                else
                                                                                                                str = str & "<option value=" & rsTypes("leavetype") &  " SELECTED>" & rsTypes("leavetype") & "</option>"                                             
                                                                                end if
                                                                                rsTypes.movenext
                                                                Loop
                str = str &   "         </SELECT>           </td></tr>" & _
                "              <tr><td>Leave Taken to Date</td><td>" & empl.Leavetaken  & "</td></tr>" & _
                "              <tr><td>Balance of Leave<BR> At Time of Application</td><td>" & rs("balanceattimeofappl")  & "&nbsp;days</td></tr>" & _
                "              <tr><td>Supervisor</td><td>" & supervisor.name  & "</td></tr>" & _
                "              <tr><td>Date Signed By supervisor</td><td>" & rs("supervisordate")  & "&nbsp;</td></tr>" & _
                "              <tr><td>Head Of Department</td><td>" & HOD.name  & "</td></tr>" & _
                "              <tr><td>Date Signed By HOD</td><td>" & rs("dateapproved")  & "&nbsp;</td></tr>" & _
                "              <tr><td>Status Of Application</td><td>" & rs("status")  & "</td></tr>" & _
                "              <tr><td>Reason for Rejection</td>" & _
                "                              <td><textarea name='reasonforrejection' cols='40' rows='4'>" & rs("Reasonforrejection")  & "</textarea></td>" & _
                "              </tr>" & _
                "</table>"
                str = str & "<table align ='center'>" & _
                                "<TR><TD align='center' colspan='2'>" & _                                  
                                "              <input name='leaveid' type='hidden' value=" & session("leaveSaved")   & "></input>" & _
                                "              <input name='user' type='hidden' value=" & user  & "></input>" & _
                                "              <input name='submit' value ='Approved' type='submit' >" & _
                                "              <input name='submit' value ='Rejected' type='submit' >" & _
                                "              </TD>" & _
                                "</TR>" & _
                "</table></form></BODY><HTML>"                            
                sendemail empl.Supervisor, str, "Leave Request"
 
'***********************email message to Employee to allow Leave Cancellation before approval takes place***********************************    
'24 May 2006
 
                                'empolyee's email
                                strmsg = "<HTML><BODY>" & _                                                  
                                                empl.name &  ":<BR>" & _
                                                "Your have apply leave from " &  rs("startdate") & " (" & rs("startperiod") & ") to " & rs("enddate") & " (" & rs("endperiod") & ")." & _
                                                "<BR><BR> To cancel your leave, please click on the below button. <BR><BR>" & _
                                                "<form name='approve' " & _
                                                "action='" & conURL & "Leave_system/cancelleave.asp'" & " method='GET'>" & _
                                                "<input type='hidden' name='leaveid' value=" & session("leaveSaved") & "></input>" & _
                                                "<input type='hidden' name='user' value=" & rs("employeenum") & "></input>" & _
                                                "<input value='Cancel Leave' type='submit' id='submit' name='submit'></input>" & _
                                                "</form></BODY><HTML>"
 
                                sendemail rs("employeenum"), strmsg, "Leave Application" 'email Employee
                set empl = nothing
                set Supervisor = nothing
end if
 
 
 
'display leave info
set lv = new Leave
set rs = lv.GetLeaveInfo(session("leaveSaved"))
 
if not  (rs.EOF and rs.BOF) then
                dim employeename
                dim Supervisorname
                dim HODname
                set empl = new Employee
                empl.getEmployeeInfo(rs("employeenum"))
                employeename = empl.name              
                empl.getEmployeeInfo(rs("Supervisor"))
                Supervisorname = empl.name
                empl.getEmployeeInfo(rs("HOD"))
                HODname = empl.name      
%>
 
<table border = "1" align = "center">
                <tr><td>Leave ID</td><td><%=rs("leaveid")%></td></tr>
                <tr><td>Employee Name</td><td><%=employeename%></td></tr>
                <tr><td>Start Date</td><td><%=rs("startdate")%></td></tr>
                <tr><td>Half Day</td><td><%=rs("StartPeriod")%></td></tr>
                <tr><td>End Date</td><td><%=rs("enddate")%></td></tr>
                <tr><td>Half Day</td><td><%=rs("EndPeriod")%></td></tr>
                <tr><td>Total Working Days Applied</td><td><%=rs("totaldays")%></td></tr>
                <tr><td>Reason</td><td><%=rs("reason")%></td></tr>
                <tr><td>Date of Application</td><td><%=rs("dateapplied")%></td></tr>
                <tr><td>Type of Leave</td><td><%=rs("leavetype")%></td></tr>
                <tr><td>Supervisor</td><td><%=Supervisorname%></td></tr>
                <tr><td>Date Signed By Supervisor</td><td><%=rs("Supervisordate")%>&nbsp;</td></tr>
                <tr><td>Head Of Department (HOD)</td><td><%=HODname%></td></tr>
                <tr><td>Date Signed By HOD</td><td><%=rs("dateapproved")%>&nbsp;</td></tr>
                <tr><td>Balance of Leave At Time of Application</td><td><%=rs("balanceattimeofappl")%>&nbsp;days</td></tr>
                <tr><td>Status Of Application</td><td><%=rs("status")%></td></tr>
                <tr><td align="center" colspan = "2"><a href="applyforleave.asp">Back</a> </td></tr>
</table>
<%
 
end if
 
function sendemail(emplnum,msg,subject)
    dim objNotesSession, objNotesDoc, objNotesDb, objNotesBody
   
    Set objNotesSession = createobject("Notes.NotesSession")
   
    If objNotesSession is Nothing then
                    msgbox "Could Not create a Session of Notes", 16, "Notes Session Error."
                end if
    'call objNotesSession.Initializeusingnotesusername("IT-TeknionMalaysia","coffeetime99")
    set objNotesDB = objNotesSession.GETDATABASE("TFSMDMS1","mail/slim.nsf")
   
    'Create the mail document
    set objNotesDoc = objNotesDB.CREATEDOCUMENT
    'set objNotesDoc.ReplaceItemValue("Form", "Memo")
    set objNotesBody = objNotesDoc.CreateRichTextItem("BODY")
   
    set curEmployee = new Employee
                'Response.Write "employeenum:" & emplnum
                curEmployee.GetEmployeeInfo(emplnum)
                if curEmployee.err = ""  then
                   
                     With objNotesDoc
            .Form = "Memo"
            .subject = subject
            .Sendto = "seokbee.lim@teknion.com"
            .body = msg
            .postdate = Date
        End With
       
                    if true then 'true for real email, false if testing
                                                if objnotesdoc.send = false then
                                                                Response.write "The email could not be sent, " & _
                                                                "please notify your employee on the status of his/her leave application.<BR>"
                                                                                response.write emailmsg.log
                                                else
                                                                Response.write "<center>An email has been sent to notify " & curEmployee.Name & " of the leave application.</center><br>" 
                                                end if
                                else
                                                'response.write("To: " & curEmployee.Name & " &lt;"  & curEmployee.Email & "&gt;" & "<BR>")
                                                'response.write("From: " & emailmsg.From & "<BR>" )
                                                'Response.Write("Subject: " & emailmsg.Subject & "<BR>")
                                                'Response.Write("Body: <BR>" & emailmsg.HTMLBody & "<BR>")
                                end if                     
                else
                                Response.write(curEmployee.err)
                                Response.End
                end if
   
end function
%>
</BODY>
</HTML>
 
 
The program stop at   Set objNotesSession = createobject("Notes.NotesSession") in the SendMail function and the error message that I got was:
 
 

 

         Error Type:
         Microsoft VBScript runtime (0x800A0046)
         Permission denied: 'CreateObject'
         /Leave_system/saveleave.asp, line 168

 
I have granted full permission to everyone to the lotus notes folder and have no more idea where goes wrong that I keep on getting this error message. Appreciate very much if you could assist me on this matter.
 
Thanks a million in advance.   
 
Thanks & Regards,
Seok Bee 
 

抱歉!评论已关闭.