Coding Thread, Comparing sender's email address in VBA in Coding and Web Development; Hi,
I am a newbie in VB and trying to write a script that gets an email from a senders,captures ...
-
24th April 2012, 05:39 PM #1
- Rep Power
- 0
Comparing sender's email address in VBA
Hi,
I am a newbie in VB and trying to write a script that gets an email from a senders,captures the senders email id and compare that email id from a text file that contain email id of all teh registered users.If senders email id is found there ,scripts allow the sender to go further else send the error messgae that you are not registered.
I have done
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
emailid = myNamespace.CurrentUser.AddressEntry
'MsgBox EmailId
Sub ReadFile(sFilePathAndName)
sFilePathAndName = "C:\registeresusers\Logins.txt"
Dim sFileContents
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFilePathAndName) = True Then
Set oTextStream = oFS.OpenTextFile(sFilePathAndName, 1)
sFileContents = oTextStream.ReadAll
For Each ID In Group
intCompare = StrComp(emailid, "E-mail Address", vbTextCompare)
If intCompare = 0 Then
MsgBox "continue"
Else
SendErrorEmail item, _
"You are not allowed to go further."
Exit Sub
End If
oTextStream.Close
Set oTextStream = Nothing
End If
Set oFS = Nothing
'ReadFile = sFileContents
End Sub
I dont know where I am going wrong but the script is not checking against the email addresses of each user.
-
-
IDG Tech News
-
24th April 2012, 09:09 PM #2 
Originally Posted by
cuddle
sFileContents = oTextStream.ReadAll
For Each ID In Group
intCompare = StrComp(emailid, "E-mail Address", vbTextCompare)
I dont know where I am going wrong but the script is not checking against the email addresses of each user.
I may be missing something as only on phone so reading code hard, but what is
For each Id in group
Supposed to be? There is no group variable thus for loop never runs.
Apologies if I'm missing something obvious but can't see whats up with that but of code
Steve
-
-
25th April 2012, 12:16 AM #3
- Rep Power
- 0
Comparing sender's email address in VBA
Oh the problem is that i am not getting the sender's email id correct.It is giving the recipients email id.
Do you know how to check the sender's email id in VBscript.
for recipients email id i used the following code
Dim myolApp As Outlook.Application
' Dim myNamespace As Outlook.NameSpace
' Set myolApp = CreateObject("Outlook.Application")
'Set myNamespace = myolApp.GetNamespace("MAPI")
How can I get Sender's email address?
-
-
25th April 2012, 05:02 PM #4
- Rep Power
- 9
Try something like this (in Red)
Take a look at the code inside Red>>>>

Originally Posted by
cuddle
Hi,
I am a newbie in VB and trying to write a script that gets an email from a senders,captures the senders email id and compare that email id from a text file that contain email id of all teh registered users.If senders email id is found there ,scripts allow the sender to go further else send the error messgae that you are not registered.
I have done
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
'>>>>>>>>>>>>>>>>>
' get a handle on the Inbox
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set folderItems = myFolder.Items
' now iterate across the items in the Inbox
For Each folderItem In folderItems
' check if item is an MailItem object
If (folderItem.Class = olMail) Then
' get the sender email address
Debug.Print folderItem.Sender.Address
'....... now do your code here ......
End If
Next folderItem
'>>>>>>>>>>>>>>>>>
emailid = myNamespace.CurrentUser.AddressEntry
'MsgBox EmailId
Sub ReadFile(sFilePathAndName)
sFilePathAndName = "C:\registeresusers\Logins.txt"
Dim sFileContents
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFilePathAndName) = True Then
Set oTextStream = oFS.OpenTextFile(sFilePathAndName, 1)
sFileContents = oTextStream.ReadAll
For Each ID In Group
intCompare = StrComp(emailid, "E-mail Address", vbTextCompare)
If intCompare = 0 Then
MsgBox "continue"
Else
SendErrorEmail item, _
"You are not allowed to go further."
Exit Sub
End If
oTextStream.Close
Set oTextStream = Nothing
End If
Set oFS = Nothing
'ReadFile = sFileContents
End Sub
I dont know where I am going wrong but the script is not checking against the email addresses of each user.
-
SHARE: 
Similar Threads
-
By machin05 in forum Windows
Replies: 29
Last Post: 16th October 2008, 04:28 PM
-
By cjohnsonuk in forum Windows Server 2008
Replies: 8
Last Post: 26th September 2008, 08:58 PM
-
By thesk8rjesus in forum Network and Classroom Management
Replies: 11
Last Post: 16th September 2008, 12:32 PM
-
By Zoom7000 in forum Windows Server 2008
Replies: 1
Last Post: 11th September 2008, 09:22 AM
-
By dave-a in forum Windows
Replies: 4
Last Post: 14th May 2007, 10:10 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules