469,289 Members | 2,330 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

Check if Exchange account exists from C# .Net application

I am writing an application that needs to check if an exchange account exists on a server. I am using C# and the .NET framework, so far there seems to be no way to do this. I believe we are using Exchange 2003 servers.
May 22 '07 #1
8 10466
Plater
7,872 Expert 4TB
Exchange is a Mail Server yes?
Attempt to establish a connection with the server and supply credentials. The server will respond with a message saying they are valid or invalid.

RFC2554
(Snip-it)
Expand|Select|Wrap|Line Numbers
  1. Examples:
  2.          S: 220 smtp.example.com ESMTP server ready
  3.          C: EHLO jgm.example.com
  4.          S: 250-smtp.example.com
  5.          S: 250 AUTH CRAM-MD5 DIGEST-MD5
  6.          C: AUTH FOOBAR
  7.          S: 504 Unrecognized authentication type.
  8.          C: AUTH CRAM-MD5
  9.          S: 334
  10.          PENCeUxFREJoU0NnbmhNWitOMjNGNndAZWx3b29kLmlubm9zb2Z0LmNvbT4=
  11.          C: ZnJlZCA5ZTk1YWVlMDljNDBhZjJiODRhMGMyYjNiYmFlNzg2ZQ==
  12.          S: 235 Authentication successful.
  13.  
If you supply an invalid credential some sort of 5xx error will be returned.
In theory atleast.
May 22 '07 #2
Exchange is a Mail Server yes?
Attempt to establish a connection with the server and supply credentials. The server will respond with a message saying they are valid or invalid.

RFC2554
(Snip-it)
Expand|Select|Wrap|Line Numbers
  1. Examples:
  2.          S: 220 smtp.example.com ESMTP server ready
  3.          C: EHLO jgm.example.com
  4.          S: 250-smtp.example.com
  5.          S: 250 AUTH CRAM-MD5 DIGEST-MD5
  6.          C: AUTH FOOBAR
  7.          S: 504 Unrecognized authentication type.
  8.          C: AUTH CRAM-MD5
  9.          S: 334
  10.          PENCeUxFREJoU0NnbmhNWitOMjNGNndAZWx3b29kLmlubm9zb2Z0LmNvbT4=
  11.          C: ZnJlZCA5ZTk1YWVlMDljNDBhZjJiODRhMGMyYjNiYmFlNzg2ZQ==
  12.          S: 235 Authentication successful.
  13.  
If you supply an invalid credential some sort of 5xx error will be returned.
In theory atleast.
This will work except, I will need to check for accounts other than my own, so therefore I would not have the password. I need to be able to do something like above and just get a simple exists/ or not feedback.
May 22 '07 #3
Frinavale
9,735 Expert Mod 8TB
This will work except, I will need to check for accounts other than my own, so therefore I would not have the password. I need to be able to do something like above and just get a simple exists/ or not feedback.
Does your program ask the user for their email address and password?
May 22 '07 #4
Plater
7,872 Expert 4TB
If you are lucky your exchange server will be the smart picky kind.
Then when you go to compsoe a fake email, you have to send it a list of recipients.
For example if your mail server controls @mydomain.com
You start a mock email and send it a RCPT TO with the email address.
If you send say Jones@mydomain.com it will look in it's own records for a Jones user.
Here is an exmple from the RFC pages on SMTP:
Expand|Select|Wrap|Line Numbers
  1. S: RCPT TO:<Jones@mydomain.com>
  2. R: 250 OK
  3.  
  4. S: RCPT TO:<Green@mydomain.com>
  5. R: 550 No such user here
  6.  
  7. S: RCPT TO:<Brown@mydomain.com>
  8. R: 250 OK
  9.  
  10. S: RCPT TO:<eric@mydomain.com>
  11. R: 552 Recipient storage full, try again in another transaction
  12.  
"550 No such user here" = user not on exchange server
"250 OK" = user exists

Be careful though, because you could get something like:
"552 Recipient storage full, try again in another transaction" which is an error, but the user still exists

EDIT:
Found this....
Expand|Select|Wrap|Line Numbers
  1. -------------------------------------------------------------
  2.  
  3.                     Example of Verifying a User Name
  4.  
  5.          Either
  6.  
  7.             S: VRFY Smith
  8.             R: 250 Fred Smith <Smith@mydomain.com>
  9.  
  10.          Or
  11.  
  12.             S: VRFY Smith
  13.             R: 251 User not local; will forward to <Smith@otherdomain.com>
  14.  
  15.          Or
  16.  
  17.             S: VRFY Jones
  18.             R: 550 String does not match anything.
  19.  
  20.          Or
  21.  
  22.             S: VRFY Jones
  23.             R: 551 User not local; please try <Jones@otherdomain.com>
  24.  
  25.          Or
  26.  
  27.             S: VRFY Gourzenkyinplatz
  28.             R: 553 User ambiguous.
  29.  
  30.                                Example 3
  31.  
  32.       -------------------------------------------------------------
  33.  
  34.  
May 22 '07 #5
Does your program ask the user for their email address and password?
no, I only get a user ID and thats it, I use this to look up some information, they some of the them have an additional exchange account and thats what I need to know. I'm kind of thinking of giving up on this since there seems to be no 'ez' way to interface the .net framework and ms exchange server.
May 23 '07 #6
Plater
7,872 Expert 4TB
The VRFY <username> command shoulda worked fine for you.

Building your own SMTP class would make you happy. (sarcasm hehe)
May 23 '07 #7
The VRFY <username> command shoulda worked fine for you.

Building your own SMTP class would make you happy. (sarcasm hehe)
haha, you'r right, I'm going to give that a try seems ez enought. I suppose I can use the System.Net classes to make do the request/response mechanics right?
May 23 '07 #8
Plater
7,872 Expert 4TB
System.Net.Sockets.TcpClient
If all you need to do is VRFY, it should be really easy

BEFORE you get too crazy with it, should should use like hyperterminal to see if your exchange server supports it.
I just checked on my mailserver (not an exchange server) and it went out of it's way to advertise that it supports VRFY/EXPN, but when I went to use them it just reported not supported. It's possible that I would need to AUTH myself before it worked, but converting my username/pass to base64 string in my head would be hard
May 23 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Manuel Krummenacher | last post: by
2 posts views Thread by George Durzi | last post: by
reply views Thread by Mostro | last post: by
2 posts views Thread by Joris De Groote | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.