cuddle Posted April 24, 2012 Posted April 24, 2012 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.
Steve21 Posted April 24, 2012 Posted April 24, 2012 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
cuddle Posted April 24, 2012 Author Posted April 24, 2012 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?
mrwITch Posted April 25, 2012 Posted April 25, 2012 Take a look at the code inside Red>>>> 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now