+ Post New Thread
Results 1 to 4 of 4
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 ...
  1. #1

    Join Date
    Apr 2012
    Location
    Portland
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    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.

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,656
    Thank Post
    324
    Thanked 506 Times in 474 Posts
    Rep Power
    177
    Quote Originally Posted by cuddle View Post

    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

  3. #3

    Join Date
    Apr 2012
    Location
    Portland
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    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?

  4. #4

    Join Date
    Feb 2009
    Posts
    45
    Thank Post
    1
    Thanked 5 Times in 5 Posts
    Rep Power
    11

    Try something like this (in Red)

    Take a look at the code inside Red>>>>


    Quote Originally Posted by cuddle View Post
    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:
+ Post New Thread

Similar Threads

  1. Replies: 29
    Last Post: 16th October 2008, 04:28 PM
  2. Exchange 2008 : Can't type in "short form" email address
    By cjohnsonuk in forum Windows Server 2008
    Replies: 8
    Last Post: 26th September 2008, 08:58 PM
  3. Hide Email Address from the 'To' in a sent email
    By thesk8rjesus in forum Network and Classroom Management
    Replies: 11
    Last Post: 16th September 2008, 12:32 PM
  4. Replies: 1
    Last Post: 11th September 2008, 09:22 AM
  5. changing email address in pdf doc's
    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
  •