Problem checking senderemailaddress with VBA

Rob4077
Rob4077 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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

Author

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
Commented:
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

Author

Commented:
Sorry for the delay in finalising this. I am finally back to it and will use your suggestion. Thanks

Commented:
Tnx :-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial