Solved

Outlook.Mailitem.Body datatype

Posted on 2011-03-15
22
1,027 Views
Last Modified: 2012-05-11
Hi Experts,
    I ran into a problem where after retrieving the mailitem body text, the result appears what i see isn't what i get. In my case:

Dim objOutlook As Outlook.Application
Dim oMail As Outlook.MailItem
Set oMail = Application.ActiveInspector.CurrentItem
Dim strBody As String
strBody = oMail.Body

after these codes I found strBody string is a whole line of string which looks fine to me. then i started my processing:

if strBody = "Daily" then
  i = 1
End if

For illustrating purpose, my strBody in my Email returns me "Daily" as i debug.print mailitem.body in immediate window. but when i run the if statements, it never went through 'Then'.
It turns out to me that strBody isn't just "Daily" as what i saw in immediate window.

I also did a check on mailitem.bodyformat, it is plaintext. Does anybody have a clue how do i solve this issue?
0
Comment
Question by:miketonny
  • 6
  • 4
  • 3
  • +4
22 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35144292
Perhaps if you call Trim()?
strBody = oMail.Body.Trim()

Open in new window

0
 
LVL 2

Author Comment

by:miketonny
ID: 35144457
sry i forgot to mention it's in Outlook 2010 vba macro,
I tried Trim(strBody) before, it's not working as it should.
I see from immediate window strBody = "Daily",
but it just dont pass over 'Then'
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 125 total points
ID: 35319660
Certain that there are no new lines and other "white space" involved? You would not see that in Immediate Window, and trim doesn't trim that - it only removes real spaces. Try what
   ? ">" & strBody & "<"
displays.
0
 
LVL 15

Accepted Solution

by:
dbbishop earned 125 total points
ID: 35319661
Try:

If Left(strBody, 5) = "Daily" Then
  i = 1
End If

 
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 35319710
can you post the msg file?
0
 
LVL 2

Author Comment

by:miketonny
ID: 35320079
? ">" & strBody & "<"
>Submission from online OEM form for applying for new emailed pricelists.Logged in users details:Customer: ROS0111Contact: EGEE ENTERPRISESPricelevel: 3IP: 121.98.129.47Email: kate@egee.co.nzRequested email details:Email: kate@egee.co.nzType: XLSXFrequency: Daily
<
that's what strBody originally has.

0
 
LVL 2

Author Comment

by:miketonny
ID: 35320100
Hi dbbishop,  that actually worked, thanks.
do you mind tell me why though?
I use :
If strFrequency= "Daily" then
  intFreq = 1
Else
    intFreq = 5
End if
which is not working, but
If Left(strFrequency, 5) = "Daily" Then
    intFreq = 1
Else
    intFreq = 5
End If

this worked.
strFrequency's value is "Daily" for both cases. I'm curious why same value returns me different results
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 35320245
Apparently there is a character after Daily in the email message

0
 
LVL 15

Expert Comment

by:dbbishop
ID: 35320313
As mlmcc stated, there may be a 'control character' following the actual text. These are typically not displayable characters.

You can run a little test if you're up to it:

strBody = oMail.Body
debug.print len(strBody)
For i = 1 To Len(strBody)
    Debug.Print ASCII(MID$(strBody, i, 1)
Next i

This should give you:
68      ' D
97      ' a
105    ' i
108    ' l
121    ' y
...

Anything after the 121 is extraneous data.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 68

Expert Comment

by:Qlemo
ID: 35321469
That is what I tried to express in http:#35319660 ...
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 125 total points
ID: 35322332
Hi, miketonny.

Trim only removes spaces.  There may be a control character in the body that you can't see.  How about using InStr to test for the presence of "Daily" in the body?
0
 
LVL 30

Assisted Solution

by:MlandaT
MlandaT earned 125 total points
ID: 35322624
you can remove all whitespace characters from the message body with this regular expression:

	strBody = oMail.Body
	Dim reg As New Regex("\s*")
	strBody = reg.Replace(strBody, "").trim()

Open in new window


That should take out all the funny invisible characters. The
0
 
LVL 30

Expert Comment

by:MlandaT
ID: 35322632
If it is enough to just detect the presence of the word "Daily" in the body, you can even just use the Like operator...

If strFrequency Like "*Daily*" then
  intFreq = 1
Else
    intFreq = 5
End if

Open in new window

0
 
LVL 2

Author Comment

by:miketonny
ID: 35328134
Hi dibishop, you're right, i ran the test and there was a 10 & 13 after 121, so that's the carriage return and linefeed at the end of the word, I now know how to test that.
thx guys for the help, much appreciated
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 35328329
I mentioned that in http:#a35319660 ..., and have been first to do so.
0
 
LVL 2

Author Comment

by:miketonny
ID: 35328700
sry Qlemo i missed that when i tick the boxes, is there any other way to assign points?
0
 
LVL 2

Author Comment

by:miketonny
ID: 35328910
cool all set now, thanks for reminding my mistake, i just saw the reference
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 35328917
Thank you for taking the additional effort to do a fair split.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now