VB.NET program to monitor emails on exchange server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seraieis
    New Member
    • Apr 2008
    • 60

    #1

    VB.NET program to monitor emails on exchange server

    Good afternoon all!

    I'm having trouble here, and I've visited about half the sites on the internet to fix it, and I'm not having luck.

    I'm trying to write a VB.NET application that will monitor an exchange server mailbox and download any attachments in received messages. However, I cannot find a way to connect to the server.

    This is what I have to far:
    Code:
            Dim server As New System.Net.Mail.SmtpClient("STHEMB002", 25)
            Dim msg As New System.Net.Mail.MailMessage()
    
            msg.To.Add("Bob.Dole@company.com")
            msg.From = New System.Net.Mail.MailAddress("Bob.Dole@company.com")
            msg.Subject = "test"
    
            server.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
            server.UseDefaultCredentials = False
            server.Credentials = New System.Net.NetworkCredential("user", "pass", "STHEMB002")
    
            server.Send(msg)
    I know that within outlook, the mailbox requires password authentication, so I tried to add a crediential before sending, however the "server.Send(ms g)" line generates the following error:
    Code:
    System.Net.Mail.SmtpException was unhandled
      Message="Failure sending mail."
      Source="System"
      StackTrace:
           at System.Net.Mail.SmtpClient.Send(MailMessage message)
    If anyone has any suggestions, I'd love to listen! I've only messed with Outlook and COM functions, and I haven't done anything like this, so I'm not even sure where to start.

    Thanks!
  • stoogots2
    New Member
    • Sep 2007
    • 77

    #2
    It's been about a year since I dealt with exchange, but I thought that credentials were necessary only if :

    1) the user you want to login as is not the user that is currently logged in
    or
    2) the server configuration requires a special userid and password combination

    I would check active directory and stuff a "real" user account and password into your credential field or login as a valid AD user and try it again. Assuming you have tried this, verify your network connectivity/server configuration by using Telnet to connect via SMTP/TCP.
    Here is how...
    from CMD prompt: telnet servername tcpportnumber
    then: HELO yourfulldomainn ame.com
    then: mail from:<sender@do main.com>
    then: rcpt to:<recipient@d omain.com>
    then: data
    then: Subject: and a subject if you want
    then: Any kind of message text
    then: .

    A blank line with a period ends the message. If you get through all of those commands and get a message accepted statement from the server, then the problem is within your code/use of the SMTPClient class.

    Comment

    • seraieis
      New Member
      • Apr 2008
      • 60

      #3
      Originally posted by stoogots2
      It's been about a year since I dealt with exchange, but I thought that credentials were necessary only if :

      1) the user you want to login as is not the user that is currently logged in
      or
      2) the server configuration requires a special userid and password combination

      I would check active directory and stuff a "real" user account and password into your credential field or login as a valid AD user and try it again. Assuming you have tried this, verify your network connectivity/server configuration by using Telnet to connect via SMTP/TCP.
      Here is how...
      from CMD prompt: telnet servername tcpportnumber
      then: HELO yourfulldomainn ame.com
      then: mail from:<sender@do main.com>
      then: rcpt to:<recipient@d omain.com>
      then: data
      then: Subject: and a subject if you want
      then: Any kind of message text
      then: .

      A blank line with a period ends the message. If you get through all of those commands and get a message accepted statement from the server, then the problem is within your code/use of the SMTPClient class.
      I followed the steps you suggested, however I was unable to use telnet. It keeps giving me an error along the lines of "HELO isn't a valid command".

      I also tried using CDO to connect to the exchange server (using my user id and password) and was unsuccessful. There has to be something I'm missing, however I'm not sure what it is. Are there any other ports that Exchange uses to send/receive email?

      Comment

      • stoogots2
        New Member
        • Sep 2007
        • 77

        #4
        The ports are all configurable at the server.

        If ...
        "telnet servername 25"
        did not give you a line of text at the top of the screen in your telnet session, then your SMTPClient will not work. I don't know how your got that "unrecogniz ed command" unless you were at a CMD prompt when you typed it. The command in quotes should open a session with the server (just as if you were another smtp server across the network). It should give you a number on the top left of the screen and if it is 500, you got an error that necessitates talking with your exchange admins. There should be a blinking cursor, not another C:\> prompt. You might need to make a request to become a relay to the server (they generally get your IP or hostname and put it into an allowed list).



        you don't get a line of text at the top of the screen?
        It sounds like a server config thing if that is the case. You must be able to ping by IP address

        Comment

        Working...