How to add default signature and new tables in a new outlook mail by testcomplete - vbscript

I am trying to send new outlook mail by testcomplete using vb scripting language .In that new mail i want to add new tables and keep default signature at bottom of mail by testcomplete. i am getting VB script run time error when i am using this code..please check the code and suggest me the correct methods i have to use to add new tables and signature
Function SendMail()
Dim objOutLook, NamespaceMAPI,objNewMail, fso, SendReceiveControls
Dim strTo,strCc ,strBcc ,strSubject, AccountName,strAttachmentPath
strSubject="test"
strTo=yyy#yy.com
strCc=XXX#XX.com
strBcc =zzz#zzz.com
strAttachmentPath="c:\text.txt"
Set objOutLook = CreateObject("Outlook.Application")
Set NamespaceMAPI = objOutLook.GetNamespace("MAPI")
Set objNewMail = objOutLook.CreateItem(olMailItem)
objOutLook.DisplayAlerts =True
objNewMail.TO = strTo
objNewMail.CC = strCc
objNewMail.BCC=strBcc
objNewMail.Subject = strSubject
objNewMail.Body = strMsg
If strAttachmentPath <> "" Then
Set fso =CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strAttachmentPath) Then
objNewMail.Attachments.Add(strAttachmentPath)
objNewMail.GetDefaultsignature() 'script run time error occured here
objNewMail.addtable(4,3)
objNewMail.display
Else
msgbox "Attachment File Does not exists"
End If
End If
objOutLook.Quit
''''''' Releasing objects '''''''
Set objOutLook =Nothing
Set objNewMail = Nothing
Set fso = Nothing
End Function
please help me.. thanks in advannce....

See if this or this helps. They are alternative methods to yours.
I prefer to use the 2nd option, the CDO method, you just need to take atention to the fact that usually this email goes to the spam inbox, you need to manually add it to your secure contacts

Related

VBS If file is open

I've got a simple program than scans data into a spreadsheet along with a timestamp, then you can either update the data by saving, or quit and exit and save.
The only issue I've been stuck on for a day or so is to work around the error handling of the case of the spreadsheet being already open. Id like to have something like this;
if file is open THEn msgbox("File is open, close file and start again")
WScript.Quit
Option Explicit
DIM oFs: Set oFs = CreateObject("Scripting.FileSystemObject")
DIM objExcel, strExcelPath, objSheet
DIM ib
DIM msg1
DIM msg2
strExcelPath = "c:\temp\Example.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
DO
ib=inputbox("SCAN NAME, SCAN LOTS"&vbCrLf&"TO UPDATE,SCAN ""UPDATE."""&vbCrLf&"TO EXIT, SCAN ""QUIT.""","Picklot Passout Database")
IF ib="" THEN
msg1=MsgBox("You must scan either a NAME or LOT NUMBER."&vbCrLf&"If you want to exit, scan QUIT."&vbCrLf&"Click OK to continue.",vbokonly,"Cannot Insert Blank Data")
ELSEIF ib= "QUIT" OR ib= "quit" THEN
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
set objExcel = Nothing
Set oFs = Nothing
ELSEIF ib="update" OR ib="UPDATE" THEN
objExcel.ActiveWorkbook.Save
msg2=MsgBox("Update Complete.",vbokonly,"Database Updated")
ELSE
objSheet.Range("A2").EntireRow.Insert
objSheet.Cells(2, 1).Value = ib
objSheet.Cells(2, 2).Value=(now)
END IF
LOOP WHILE NOT ib="quit" AND NOT ib="QUIT"
This may help point you in the right direction. Sorry for the rushed, lowercase syntax and unconventional indentations (do not follow my bad practice - keep yours! :D), I wrote it in notepad you see - but it has been tested successfully.
Anyhow, with reference to your code, I have restructured it in a bad manner, familiar to me, adding the functionality you specify. Essentially the task manager application list is checked for a running instance of the "example" Excel file (depending on what version of excel you're using the syntax will differ).
If found it will make it the active window (thereby preventing a read only duplicate instance initiating). If no instance is found it will open "example.xlsx", in this case using a relative path to the script itself. A subroutine is then called to do the business with the cells...
I have written it in such a way to try keep your specs as well as maintain the "OK" and "Cancel" buttons explicitly functional. Please feel free to tinker with this, you may need to address the path and instr lines differently. I hope it helps! All the best.
path=createobject("scripting.filesystemobject").getparentfoldername(wscript.scriptfullname)
excelpath=path&"\example.xlsx"
set objword=createobject("word.application")
set coltasks=objword.tasks
i=0
for each objtask in coltasks
name=lcase(objtask.name)
if instr(name, "microsoft excel - example") then
i=1
end if
next
if i=1 then
wscript.echo "An active instance of ""example.xlsx"" has been found"
set objexcel=getobject(excelpath)
call UPDATER
else
set objexcel=createobject("excel.application")
objexcel.workbooks.open(excelpath)
set objsheet=objexcel.activeworkbook.worksheets(1)
objexcel.visible=true
call UPDATER
end if
sub UPDATER
do
data=inputbox("Please enter data" &vbcrlf&vbcrlf& "To save data & continue, type ""update""" &vbcrlf& "To save data & exit, type ""quit""","Excel DB Updater")
if isempty(data) then
objexcel.activeworkbook.close
objexcel.application.quit
wscript.quit()
elseif lcase(data)="quit" then
objexcel.activeworkbook.save
objexcel.activeworkbook.close
objexcel.application.quit
quit=msgbox("DB Updating complete",vbokonly,"Excel DB Updater")
wscript.quit
elseif lcase(data)="update" then
objexcel.activeworkbook.save
update=msgbox("Data save complete, press OK to continue",vbokonly,"Excel DB Updater")
elseif len(data)<>0 then
objsheet.range("A1").entirerow.insert
objsheet.cells(1, 1).value=data
objsheet.cells(1, 2).value=(now)
add=msgbox("Data added, press OK to continue",vbokonly,"Excel DB Updater")
end if
loop while len(data)>=0 and not lcase(data)="quit"
end sub

Lotus Notes - Web form agent - not sending email

I have a web form that when the button is pressed should pull a list of names from a field and send a mail. The mail isn't sending.... Here is the lotus script... thanks in advance
Sub Click(Source As Button)
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim mdoc As NotesDocument
Dim ddoc As NotesDocument
If ws.CurrentDocument.IsNewDoc Then
Call ws.CurrentDocument.Save
Set db = s.CurrentDatabase
Set view = db.GetView("deptLookup")
Set doc = ws.CurrentDocument.Document
dept$ = doc.ProcDeptAssoc(0)
Set ddoc = view.GetDocumentByKey(dept$)
If ddoc Is Nothing Then
Msgbox "Department not found"
Else
Set mdoc = New NotesDocument(db)
mdoc.Subject = "Comment made on procedure " + doc.ProcNo(0) +" - "+doc.ProcName(0)+ " by " + doc.CreatedBy(0)
Dim rtitem As New NotesRichTextItem(mdoc, "Body")
Call rtitem.AppendText("Requires the approval of " +doc.approver(0)+", click the link and the approve or deny the request. ")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink(doc, "CommentsDoc")
receipients = ddoc.NotifyName
mdoc.SendTo = receipients
mdoc.Send(False)
End If
Else
Call ws.CurrentDocument.Save
End If
ws.CurrentDocument.Close
End Sub
If you use a form instead of an XPage you will need to place your code in the agent and set that agent as WebQuerySave agent of the form. LotusScript under the button will not run when accessed from the web.
Also you cannot use UI classes like NotesUIWorkspace in backend code.
You can move that Lotusscript code to an agent with trigger "agent list selection" and target "none" and from the web form to use a #formula (not lotusscript) button with this #command:
#Command([RunAgent];"NAME_OF_YOUR_AGENT");
Panu Haaramoroperties is right when he says than the Lotusscript click event in buttons doesn't works from web forms but #commands do work.
He es also right when he said the you have to replace NotesUIWorkspace reference. You can begin using :
s.documentContext
instead
ws.CurrentDocument

Avoiding execution security alert in lotus notes

I created a button for polling in notes email body and then send it to a group of members for their voting. When the users, vote they get a execution security alert for each action the script. The following is the code placed in the Yes button.
Dim session As New notessession
Dim ws As New notesuiworkspace
Dim db As notesdatabase
Dim doc_poll As NotesDocument
Set db = session.getDatabase("Server Name", "ApplicationTesting/Polling.nsf")
Set doc_poll = db.CreateDocument()
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Dim doc As notesdocument
Set doc = uidoc.Document
If doc.temp(0) <> "yes" Then
v_val= ws.Prompt(3,"Family member count","No of Members ?")
Call doc.ReplaceItemValue("temp","yes")
Call doc.Save(True,True)
Call doc.Sign
Call doc.Save(True,True)
doc_poll.Form = "Fo-PollReport"
Call doc_poll.ReplaceItemValue("etxtUserName", session.CommonUserName )
Call doc_poll.ReplaceItemValue("etxtMembers", Cint(v_val))
Call doc_poll.save(True,False)
Messagebox"Your voting has been sent to HR", 64,"Voting"
Else
Messagebox "Your voting is already been sent to HR. Please contact HR directly,in case of any change in voting ",16, "Voting"
End If
How do i avoid execution security alert ?
To avoid the ECL alerts the signature that the code is signed under would need to be on their ECL list and allow the related commands that are hitting the alerts.
You could push that signature down via a policy (security settings IIRC).

Get EntryID of new mail

We made a script that automatically opens the Microsoft Outlook new mail window. Some things have to be filled in already. This works so far:
Set Arguments = WScript.Arguments
If Arguments.Count > 4 Then
Set Outlook = CreateObject("Outlook.Application")
Set BodyObject = CreateObject("Scripting.FileSystemObject")
Set Mail = Outlook.CreateItem(0)
Mail.To = Arguments(0)
Mail.CC = Arguments(1)
Mail.BCC = Arguments(2)
Mail.Subject = Arguments(3)
Set BodyFile = BodyObject.OpenTextFile(Arguments(4))
Mail.Body = BodyFile.ReadAll
BodyFile.Close
For Counter = 5 to (Arguments.Count - 1)
Mail.Attachments.Add Arguments(Counter)
Next
Mail.Display
End If
But know we want to know if that mail gets sent by the user and we also want to know the EntryID of that mail, so we can look it up later.
Now Mail.Display doesn't return anything and the program just ends. It does not wait until the window gets closed. So after Mail.Display, there should be something like: Mail.Wait, or a Mail send event so we can get the EntryID.
Could someone help us out?
Thanks in advance,
Gillis and Emiel
I just found a probable solution from here:
You need to wait and get the EntryID
value after the item has been
delivered from the Outbox. To do this,
subscribe to the Folder.Items.ItemAdd
event on the Sent Items folder. That
event passes the newly added -- i.e.
newly sent -- item as its argument.
The item must exist first in Outlook to have an EntryID value, use the Save Property and fetch its EntryID right after
Mail.Save
strEntryID = Mail.EntryID
I've got a sample written in VBA for saving notes from Access form to Outlook
Dim outobj As Outlook.Application
Dim outappt As Outlook.NoteItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olNoteItem)
With outappt
If Not IsNull(Me!strBody) Then .Body = Me!strBody
.Save
Me!strEID = .EntryID
End With

Sending email from webpage using Outlook

I have a webpage that has a button that sends a letter on the page to an email recipent. Currently we are use Lotus Notes and with VB script, we are able to create an object of Lotus Notes and one of the properties for this object is PutInFolder. After the user clicks on the email button, the script will send the email and also put save the email in a certain folder on the user's computer. Our company is now switching over to Outlook 2007 and I'm looking to do the same thing with an Outlook object instead. Our development is local intranet only, and there are only a few users that will have access to this. Anyway, my problem is I cannot seem to find the same functionality with an Outlook Application.
I do have the send of the email currently working using this logic. Does anyone have any ideas on how to save the email in the user's outlook folder? I tried looking for a list of properties that I can call but I cannot find anything searching. Maybe I don't have the right terminalogy in the searches.
Thank you.
sub send_mailvb(sendto, sendcc, sendbcc, subject_text, body_text, attachment1, attachment2, attachment3)
'Open mail, adress, attach report
dim objOutlk 'Outlook
dim objMail 'Email item
dim strMsg
const olMailItem = 0
'Create a new message
set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
' Setup send to
objMail.To = sendto
' Setup send cc
If sendcc <> "" Then
objMail.cc = sendcc
End If
' Setup send bcc
If sendbcc <> "" Then
objMail.bcc = sendbcc
End If
'Set up Subject Line
objMail.subject = subject_text
'Add the body
strMsg = body_text & vbcrlf
'Add an attachments
If attachment1 <> "" Then
objMail.attachments.add(attachment1)
End If
If attachment2 <> "" Then
objMail.attachments.add(attachment2)
End If
If attachment3 <> "" Then
objMail.attachments.add(attachment3)
End If
objMail.body = strMsg
objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
'Clean up
set objMail = nothing
set objOutlk = nothing
End Sub
For future reference... I found the solution I was looking for. It wasn't too bad of a mess. Here's the modified source to replicate the Send and save email to a specific folder incase someone else comes looking. Thanks to Tester101 for the website I was looking for. Again this is vbscript imbedded in the HTML page.
sub send_mailvb(sendto, sendcc, sendbcc, subject_text, body_text, attachment1, attachment2, attachment3)
'Open mail, adress, attach report
dim objOutlk 'Outlook
dim objMail 'Email item
dim strMsg
dim myInbox
const olMailItem = 0
'Create a new message
set objOutlk = createobject("Outlook.Application")
Set objNameSpace = objOutlk.Session
set objMail = objOutlk.createitem(olMailItem)
Set myNameSpace = objOutlk.GetNamespace("MAPI")
Set myExplorer = objOutlk.ActiveExplorer
' 6 at least on my machine pointed to the Inbox (should be the same as constant olFolderInbox). Within the Inbox I have a folder called Test
Set myExplorer.CurrentFolder = myNameSpace.GetDefaultFolder(6).Folders("Test")
Set myFolder = myExplorer.CurrentFolder
' Setup send to
objMail.To = sendto
' Setup send cc
If sendcc "" Then
objMail.cc = sendcc
End If
' Setup send bcc
If sendbcc "" Then
objMail.bcc = sendbcc
End If
'Set up Subject Line
objMail.subject = subject_text
'Add the body
strMsg = body_text & vbcrlf
'Add an attachments
If attachment1 "" Then
objMail.attachments.add(attachment1)
End If
If attachment2 "" Then
objMail.attachments.add(attachment2)
End If
If attachment3 "" Then
objMail.attachments.add(attachment3)
End If
objMail.body = strMsg
// objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
objMail.Save
objMail.Move(myFolder)
objMail.Send
'Clean up
set objMail = nothing
set objOutlk = nothing
End Sub
I found this article. It might be something tha could help.
http://www.outlookcode.com/codedetail_print.aspx?id=1041
If not this site has great resources for working with outlook.
It looks like the MailItem object has a Save method, as well as a SaveAs method. So you should be able to do something like this.
objMail.SaveAs "C:\Test.msg", 3
The 3 is to save the message in olMSG format see OlSaveAsType Enumeration.
I have a solution. We've decided to bcc the person sending the email and then use an outlook rule to move the email to the specified outlook folder. Thanks to everyone that replied.

Resources