Problem checking senderemailaddress with VBA

I have developed some VBA that is intended to create an auto reply to a correctly formatted message. However step one of the process is to check the senderemailaddress and I am having trouble with senders from my own domain. Instead of the senderemailaddress coming in as username@mydomain.com it's coming in as something like: "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FY....LT)/CN=RECIPIENTS/CN=5959...E-USERNAME"  How can I get the normal format username to test for validity
LVL 1
Rob4077Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrTribosCommented:
In the string... is the username accurately presented in the string?  If so, can you just append the username to your domain name to recreate the email address?

There are a few ways to extract a username from a string, but you may need to identify a pattern...

e.g.  assuming the username is preceded by "..." and forms the rest of the string (and there are no other occurrences of "..." in the string) then you could do something like:
myUsername = split(string, "...")(0)

Open in new window

Rob4077Author Commented:
Hi, thanks for your comment. I didn't post the full address as I wasn't sure of security implications with other people on the net but I will now post it in full senderemailaddress string, albeit in a scrambled format. As you can see the last part of the address is the username which happens to be the user name part of the true email address so I can do an instrrev and grab what comes after the last "-" in the string but I was hoping there would be a more robust option. Is there no safer way?

/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBPI3I3SYDIT)/CN=RECIPIENTS/CN=5978029F591240D597AA8DEF8111AF2E-USERNAME


The senderemailaddress I am searching for is username@mydomain.com.au
DrTribosCommented:
I must confess that I am no expert in exchange... there may well be some parameter / variable that you can query to get the required information.

My suggestion is for a workaround, which, if the username is displayed faithfully should work - sure it's a bit of a hack....

some thoughts, a username could potentially have a '-' character in it... so so I would look to split the string at '=' signs.  I like arrays for this...  but you could just as easily use a different approach.

Dim myString as String
myString = "/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBPI3I3SYDIT)/CN=RECIPIENTS/CN=5978029F591240D597AA8DEF8111AF2E-USERNAME"
myString = split(myString, "=")(Ubound(split(myString, "=")))
' should return: "5978029F591240D597AA8DEF8111AF2E-USERNAME"

Open in new window


Perhaps then it is safe to assume "5978029F591240D597AA8DEF8111AF2E-USER-NAME" only has the 1st '-' and any other '-' is part of the User-Name? (Note that I added a '-' to the User-Name to illustrate...)  If so:
myString = Split(myString, "-", 2)(1)
' Should return USER-NAME

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob4077Author Commented:
Sorry for the delay in finalising this. I am finally back to it and will use your suggestion. Thanks
DrTribosCommented:
Tnx :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.