|
|
Hi there,
i want to know if there is any way to analize the body of an received mail in vb6. This is of an add-in for outlook.
Thanks
|
|
|
|
|
|
Well,the problem is that i don´t know how to catch the mail body.
What i want to do is to catch the mail body to search for an <tag> and then compare with the URL.
It´s a kind of anti-Phishing.
Thanks
|
|
|
|
|
|
Thanks,it help´s for a part of the problem. And how can i search the <tag> in the body of the mail and then compare with the URL?
|
|
|
|
|
It looks like the e-mail's body is returned as a String. You can call IndexOf() to search for a substring. In this case the URL.
So, how about something like this?
Dim myUrl As String = "www.yahoo.com"
If (oMsg.Body.IndexOf(myUrl) >= 0) Then
' URL found in body.
Else
' URL not found in body.
End If
|
|
|
|
|
But in that case we put the URL Dim myUrl As String = "www.yahoo.com".
What i want is to catch the URL that is in the body of the mail and then compare with the <tag>
|
|
|
|
|
Okay. That would be a more efficient way of handling it.
(I was hoping I could get away with something simple. )
You should use Regular Expression to identify all of the URLs in the e-mail. Perhaps an expression like this.
^(((h|H?)(t|T?)(t|T?)(p|P?)(s|S?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]*$
Here's the article I took the above string from. It contains more details. There are plenty of other articles like this on this website.
http://www.codeproject.com/csharp/regex2.asp[^]
I hope this helps!
|
|
|
|
|
Thanks for your msg´s
I tried to use that expression like this:
Public Sub ProcessInbox()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Outlook.Attachment
Dim iMsgCount As Integer
Dim myUrl As String = (^(((h|H?)(t|T?)(t|T?)(p|P?)(s|S?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]*$)
Dim oMessage As Outlook.MailItem
Dim iCtr As Long, iAttachCnt As Long
Dim sFileNames As String
Dim aFileNames() As String
'get reference to inbox
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
Debug.Print "Total Items: "; oFldr.Items.Count
Debug.Print "Total Unread items = " & oFldr.UnReadItemCount
For Each oMessage In oFldr.Items
With oMessage
'basic info about message
Debug.Print .To
Debug.Print .CC
Debug.Print .Subject
Debug.Print .Body
If oMessage.Body.IndexOf(myUrl >= 0) Then
MsgBox "URL encontrado="
' URL found in body.
Else
' URL not found in body
End If
If .UnRead Then
Debug.Print "Message has not been read"
Else
Debug.Print "Message has been read"
End If
iMsgCount = iMsgCount + 1
'save message as text file
.SaveAs "C:\message" & iMsgCount & ".txt", olTXT
.Body
'reference and save all attachments
With oMessage.Attachments
iAttachCnt = .Count
If iAttachCnt > 0 Then
For iCtr = 1 To iAttachCnt
.Item(iCtr).SaveAsFile "C:\" & .Item(iCtr).FileName
Next iCtr
End If
End With
End With
DoEvents
Next oMessage
Set oAttachment = Nothing
Set oAttachments = Nothing
Set oMessage = Nothing
Set oFldr = Nothing
Set oNs = Nothing
Set oOutlook = Nothing
End Sub
1st- I don´t know if i can use like this:
Dim myUrl As String = (^(((h|H?)(t|T?)(t|T?)(p|P?)(s|S?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]*$)
Probabli not because give´s me an error (Expected: end of statement)
Thank´s
|
|
|
|
|
First, you need to put double quotes around that string I gave you.
Second, you can't use that string like that. You need to feed it into a System.Text.RegularExpressions.Regex object, which handles the string matching for you. Regular expressions is not a small topic, so I suggest you read some articles on it.
Try looking at this article. The code is in C#, but the code is small and can easily be converted to VB.NET. In particular, look at the part where it talks about extracting the URL's authority. You'll probably want that part to match against your tags.
http://www.cambiaresearch.com/cambia3/snippets/csharp/regex/uri_regex.aspx[^]
|
|
|
|
|
Thanks a lot!!!
|
|
|
|
|
Hi there,
I still can´t search a string in the body of the mail.
Can you help me please???
Imports System.Reflection
Module Module1
Sub Main()
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get Mapi NameSpace.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:
' Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Outlook.Items = oInbox.Items
Console.WriteLine("Total : " & oItems.Count)
' Get unread e-mail messages.
oItems = oItems.Restrict("[Unread] = true")
Console.WriteLine("Total Unread : " & oItems.Count)
' Loop each unread message.
Dim oMsg As Outlook.MailItem
Dim i As Integer
Dim DTE As Object
Dim procura As String
DTE = Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.8.0")
For i = 1 To oItems.Count
oMsg = oItems.Item(i)
Console.WriteLine(i)
Console.WriteLine(oMsg.SenderName)
Console.WriteLine(oMsg.Subject)
Console.WriteLine(oMsg.ReceivedTime)
Console.WriteLine(oMsg.Body)
Console.WriteLine("---------------------------")
If Trim(oMsg.Body) = "seis" Then
MsgBox("msg found")
End If
Next
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing
End Sub
End Module
remember that i want to find an URL (it´s still a string)
Thanks
|
|
|
|
|
Like I said before, if you want to extract all URLs from the e-mail's body, then you should use Regular Expression (ie: Regex).
I'm a bit of a newbie when it comes to regex. I think you should post a new thread in this forum asking how to extract URLs from a String via Regular Expression.
|
|
|
|
|
yes, but how do we do a search of a string??? can u example it in the code please!!!It´s very urgent because i have to give this project tomorow to my teacher!
-- modified at 23:32 Wednesday 18th January, 2006
|
|
|
|
|
Finding a sub-string within a string is easy. You just call String.IndexOf(). I showed you this before.
Dim myString As String = "I like www.google.com."<br />
If (myString.IndexOf("www.google.com") >= 0) Then<br />
' Found it!<br />
End If
Finding a particular string pattern such as an URL is a lot harder. This requires regular expression.
|
|
|
|
|
thanks Josh, but this doesn´t work or else i can´t put it working. Sorry but it´s already 5 am here and my brain is sleeping!
Can u PLEASE,HELP US!!!
Please do an example in the code that i gave u!!
THANKS!!!!!
-- modified at 23:57 Wednesday 18th January, 2006
|
|
|
|
|
No one here is going to do your homework for you.
But I'll give you some example code. It's up to you to figure out how to use it.
' Array of all URLs to search for.
Dim URLs() As String = {"google.com", _
"yahoo.com", _
"msn.com"}
Dim emailBody As String = "I like www.yahoo.com."
Dim urlName As String
Dim wasUrlFound As Boolean = False
' Traverse all known URLs.
For Each urlName In URLs
' Does this URL exist in the e-mail?
If (emailBody.IndexOf(urlName) >= 0) Then
wasUrlFound = True
Exit For
End If
Next
' Notify user if URL was found.
If (wasUrlFound) Then
MessageBox.Show("Found URL """ & urlName & """.")
End If
|
|
|
|
|
LONG LIVE Joshua Quick!!!!
Thanks a lot!!!
We will put your name in our work! :->
We breaked in the part of the search in the code, but you help us with your last response.
Once more, THANKS A LOT!!!!
|
|
|
|
|
Hi,
I have implemented a FolderBrowserDialog and it works fine except when it comes across long paths. Is there a way to pass the short version of the path to the FolderBrowserDialog when the folder is selected?
Thanks,
|
|
|
|
|
Zenly wrote: it works fine except when it comes across long paths.
Do you know why it doesn't work?
Have you tried putting double quotes around your path?
For example:
Dim path As String = """C:\Documents and Settings"""
Zenly wrote: Is there a way to pass the short version of the path
You can pass it as an 8 char long path name.
For example, the long path name to the following folder...
C:\Documents and Settings
...would turn out like this...
C:\Docume~1
I don't recommend that you construct the short path name yourself. Instead, PInvoke the Win32 function GetShortPathName().
|
|
|
|
|
The issue is not with the average long paths. But I have a path where each folder is 244 characters.
For example: H:\aaa...(244 char long)\bbb...(244 char long)\ccc...(244 char long)\
When the browse dialog opens and I drill down and click on the H:\aaa...(244 char long) folder it generates an exception at FolderBrowserDialog1.ShowDialog().
I am looking for a way so that I can use the GetShortPathName() fuction to get the shartpath and pass it to the dialog before the exception is generated.
Here is the code I am using...
Dim lvPath As String
FolderBrowserDialog1.SelectedPath = ""
FolderBrowserDialog1.ShowDialog()
If FolderBrowserDialog1.SelectedPath <> "" Then
strPath = FolderBrowserDialog1.SelectedPath
End If
Thanks,
|
|
|
|
|
The problem you're running into is a complete path cannot be more that 260(?) characters long. So in order for this to work, you'll have to shorten those folder names.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Has anyone used the menu control from The free Magic Library? I am having problems figuring out how to get it working.
I can post more if someone is out there that will be willing to help.
Thanks.
|
|
|
|