How can I get the body of an email into a memo field? I am getting an error.
I am wanting to draw in the body of the email into a memo field.
Error # 1943
MESSAGE: Member ACTIVEINSPECTOR does not evaluate to an object
USE CMCONTROL IN 0
USE CMEMAILS IN 0
local array MyFiles[1,5]
nFilesFound = ADIR( MyFiles, ALLTRIM(cmcontrol.cpath) + '*.*')
xx = 0
for i = 1 to nFilesFound
xx = xx + 1
WAIT WINDOW NOWAIT 'FortenStar® Count-O-Matic'+CHR(13)+CHR(13)+'Email Record Count: '+ ALLTRIM(STR(xx))
***********************************************************************************
*** HOW CAN I MAKE THIS WORK?
***********************************************************************************
msgfile=ALLTRIM(cmcontrol.cpath) + ALLTRIM(cmemails.csubject)
o = CreateObject("Outlook.Application")
emailmsg = o.ActiveInspector.CurrentItem
memofiledvariable = emailmsg.body
***********************************************************************************
***********************************************************************************
***********************************************************************************
insert into cmemails (cprimary, csubject, ddate, dtime, cattribs, mbody) values (generateGuid(26), MyFiles[ i, 1], MyFiles[ i, 3], MyFiles[ i, 4], MyFiles[ i, 5], memofiledvariable)
endfor
USE IN SELECT('CMEMAILS')
USE IN SELECT('CMCONTROL')
You cannot access an open instance of Outlook by using CREATEOBJECT in FoxPro. You need to use GETOBJECT, and then you need to refer to the specifics you're using.
Some other suggestions:
Don't use single-letter variable names, even if they're not in the short list where FoxPro complains.
Test that o is an object and in a good state before doing anything with it.
Don't use AcitveInspector or its office-kin unless you're looking for something the user is currently looking at. In an example like this, you should be searching the API for how to filter each email item by itself.
While i'm not 100% familiar on Outlook's internal mechanism, if you've got the user's email in a directory of files ALREADY, you really should just see if you can filter that instead. MIME parsers aren't hard to come by if it's in native format, and if it's XML the DOM is easier than VBA.
Related
I have multiple account associated to my outlook, i am trying to set the From field to this one specific email i own. Looking at https://learn.microsoft.com/en-gb/office/vba/api/outlook.mailitem I should be able to accomplish this by changing the SendUsingAccount property, however, i am running into ERROR:root:(-2147352571, 'Type mismatch.', None, 1). Does anyone know why?
pythoncom.CoInitialize()
outlook = win32.Dispatch("Outlook.Application")
selection = outlook.ActiveExplorer().Selection
count = selection.Count + 1
for i in range(1, count):
message = selection.Item(i)
reply = message.ReplyAll()
newBody = "test"
for myEmailAddress in outlook.Session.Accounts:
if "#test.com" in str(myEmailAddress):
From = myEmailAddress
break
print(From.DisplayName) #prints the email i want fine
reply.SendUsingAccount = From.DisplayName #this line is giving me the error. If I remove it , the email popups fine, but the From address is defaulting to one i dont want to use
reply.HTMLBody = newBody + reply.HTMLBody
reply.Display(False)
Application.Session.Accounts collection returns Account objects, not strings. And MailItem.SendUsingAccount property takes an Account object, not a string.
Replace the line
if "#test.com" in str(myEmailAddress):
with
if "#test.com" in str(myEmailAddress.SmtpAddress):
and
Reply.SendUsingAccount = From.DisplayName
with
Reply.SendUsingAccount = From
I know that with Descriptive programming you can do something like this:
Browser("StackOverflow").Page("StackOverflow").Link("text:=Go To Next Page ", "html tag:=A").Click
But is it possible to create some kind of string so I can assign more than one data value and pass it as single variable? I've tried many combinations using escape characters and I always get error.
For example in the case above, let's say I have more properties in the Page object, so I'd normally have to do something like this:
Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")...etc...
But I'd like to pass "name:=StackOverflow", "html id:=PageID" as a single variable, so when writing many objects I'd only have to write:
Browser(BrowserString).Page(PageString).WebEdit("name:=asdfgh")
And the first part would remain static, so if the parents' data needs to be modified I'd only have to modify two variables and not all the objects created in all libraries.
Is it possible?
If I was not clear enough please let me know.
Thank you in advance!
I think what you're looking for is UFT's Description object
This allows you finer grained control on the description since in descriptive programming all values are regular expressions but with Description you can turn the regular expression functionality off for a specific property.
Set desc = Description.Create()
desc("html tag").Value = "A"
desc("innertext").Value = "More information..."
desc("innertext").RegularExpression = False
Browser("Example Domain").Navigate "www.example.com"
Browser("Example Domain").Page("Example Domain").WebElement(desc).Click
If you want to represent this with plain string then it's a bit more of a problem, you can write a helper function but I'm not sure I would recommend it.
Function Desc(descString)
Set ret = Description.Create()
values = Split(descString, "::")
For Each value In values
keyVal = Split(value, ":=")
ret(keyVal(0)).Value = keyVal(1)
Next
Set Desc = ret
End Function
' Usage
Browser("StackOverflow").Page("StackOverflow").WebElement(Desc("html tag:=H2::innertext:=some text")).Click
Further reading about descriptive programming.
As an alternative to Motti's excellent answer, you could also Set a variable to match your initial descriptive object and then extend it as required:
Set myPage = Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")
after which you can then use
myPage.WebEdit("name:=asdfgh")
throughout the rest of the code, so long as the myPage object stays in scope...
I want to know the mails with a particular word in the subject that were sent in the last 5 days. Here is the code snippet.
For Each m In objInbox.items
If InStr(1,UCase(m.subject), "LEAVE;",vbTextCompare) <> 0 and m.SentOn >= now-5 then
msgbox "There is a mail sent on"&m.SentOn
End If
Next
I get an error saying that
Object doesn't support this property or method:m.SentOn
If I remove m.SentOn >= now-5 condition from IF, it works as expected.
You need to make sure the item is really a MailItem object. In VB Script, you can either use the TypeName function (check for "MailItem"), or you can use the Class property (all OOM objects expose it). For the MailItem object, it will be 43.
Not every item in a mailbox folder is necessarily a MailItem.
Try adding a check on the object type before you run the check, like this:
For Each m In objInbox.Items
If TypeName(m) = "MailItem" Then
If InStr(1,UCase(m.subject), "LEAVE;",vbTextCompare) <> 0 and m.SentOn >= now-3 Then
msgbox "There is a mail sent on" & m.SentOn
End If
End If
Next
edit: modified to vbscript specifically rather than outlook-vba
I need some help working and new with arrays. I am trying to store a value in an email in an instance variable to be used at a later stage of my test. The email body contains the following string
Finally, your Reference Number us 7712342 - please quote this number
So what my tests is going to do is
visit the email page
grab that string and store as str_array = my Array. And I only need the number: 7712342
The problem i have is the email body has a whole bunch of text so not sure how to grab that particular text i need.
Once i have it then im good to carry on with my tests. but im stuck for now.
Hope to find some help with this.
Here is something i quickly wrote.
element :email_form, '.form-control'
element :go_button, '.input-group-btn'
elements :subject, '.all_message-min_text'
def check_email_and_store_ref
email = "test-3#mailinator.com"
email_body = "Finally, your Web Order Reference Number is 7754468 - please quote this in any communication with us until you receive your Subscriber Number."
email_subject_line = find_element_by_text(self.subject.first, email_body, {:text_element => 'header', :partial_match => true})
ref_number = email_bidy.scan(/\d+/)
Capybara.visit 'https://www.mailinator.com/'
email_form.set email
go_button.click
email_subject_line.click
puts ref_number
#I can now use the above ref number in another method within my class
end
Use String#Scan
> email_body = "Finally, your Reference Number us 7712342 - please quote this number"
> reference_no = email_body.scan(/\d+/)
#=> ["7712342"]
I have worked on how to get performance data.
new counter i need to add in my requiremnet, is "memoryPagesPerSec "
I have use inbuild class to get this counter, but not get the value
it is always zero, while i check in perfmon.exe, it gives some values.
Can some one tell me the reason, or what is the alternate solution in WMI query to get this counter value.
My current code is....
var s1 = new System.Diagnostics.PerformanceCounter("Memory", "Pages/sec");
string s2 = s1.NextValue().ToString();
Console.WriteLine("Test Memory: " + s2.ToString());
I want to change using WMI and need to check this?
Any solution for WMI query for this counter?
try this:
select PagesPersec FROM Win32_PerfFormattedData_PerfOS_Memory