Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:01:39+00:00 2026-06-01T12:01:39+00:00

We have an old legacy SQL 2000 server (the last in the farm) –

  • 0

We have an old legacy SQL 2000 server (the last in the farm) – We’ve been unable to get rid of this server as it uses xp_findnextmsg, xp_readmail etc to monitor a mailbox (via mapi) and import all email to that address into a database. The database contains simple tables that store “from”, “to”, “subject”, “body”, “Sent Date” & so on.

As you may know, the procs above are no longer in use in SQL 2005+

This table is read from dozens of internal systems, for instance emails to this mailbox can be automatically picked up by our helpdesk systems & create calls etc.

My question is this: what it the easiest / modern way of doing this in SQL 2008+? Is it going to be a case of writing a .net binary / service that will use smtp or something to connect to a mailbox and insert the data into SQL or is there a simpler way to do it? (SSIS / 3rd party tools / pre-existing code / projects?)

Just thought I’d ask before i start writing something – no point re-inventing the wheel as it were.

PS: The Mailbox in question is an exchange 2010 mailbox.

Edit: This functionality was hinted to be re-introduced in 2008 & dbmail: http://connect.microsoft.com/SQLServer/feedback/details/126167/xp-readmail-replacement-for-sql-2005 but it looks like it failed to materialise!

Edit 2: I’ve just found a decent code sample here that utilises the new web services in exchange 2007+: http://social.msdn.microsoft.com/forums/en-US/sqltools/thread/dd2b465b-b1d2-4c0d-82ec-c36c6c482d5d – experimenting in progress (has anyone ever worked with SQL and the Exchange web services?)

Edit 3: All done! I knocked up a .net service that sits on our exchange server and monitors a mailbox & pushes any new mail into SQL. Incase others have a similar question and need some sample code to get started – here is some rough code (chopped out of my service – replaced parameterised SQL with basic dynamic SQL for easy reading): (Note: you’ll need the EWS API 1.1 dll)

Imports Microsoft.Exchange.WebServices.Data

Dim ExchangeUrl As String = "https://DOMAIN.co.uk/ews/exchange.asmx"
Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
service.Url = New Uri(ExchangeUrl)
service.Credentials = New WebCredentials("USER@DOMAIN.CO.UK", "PASSWORD")
Dim findResults As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, New ItemView(1000))
If findResults.Count > 0 Then
    service.LoadPropertiesForItems(findResults.Items, New PropertySet(BasePropertySet.FirstClassProperties))
End If

For Each item As Item In findResults.Items
    Dim CurrentEmail As EmailMessage = item

    '#### Grab Email Information
    E_ID = CurrentEmail.InternetMessageId.ToString()
    If CurrentEmail.Sender.Address.ToString() <> "" Then
        E_From = Replace(CurrentEmail.Sender.Address, "'", "''")
    Else
        E_From = Replace(CurrentEmail.Sender.Name, "'", "''")
    End If
    E_From = Replace(CurrentEmail.Sender.Address, "'", "''")
    E_To = Replace(CurrentEmail.DisplayTo, "'", "''")
    E_CC = Replace(CurrentEmail.DisplayCc, "'", "''")
    E_Subject = Replace(CurrentEmail.Subject, "'", "''")
    E_Body = Replace(CurrentEmail.Body.Text, "'", "''")
    E_Received = CurrentEmail.DateTimeReceived.ToString("dd/MM/yyyy HH:mm:ss")
    E_Sent = CurrentEmail.DateTimeSent.ToString("dd/MM/yyyy HH:mm:ss")

    '#### Save the email into SQL
    If SqlQuery("INSERT INTO tbl_Emails ([MessageID], [From], [To], [CC], [Subject], [Body], [Received], [Sent]) VALUES ('" & E_ID & "', '" & E_From & "', '" & E_To & "', '" & E_CC & "', '" & E_Subject & "', '" & E_Body & "', CONVERT(DATETIME, '" & E_Received & "', 103), CONVERT(DATETIME, '" & E_Sent & "', 103))") = True Then
        item.Delete(DeleteMode.HardDelete)
    End If
Next
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:01:40+00:00Added an answer on June 1, 2026 at 12:01 pm

    The first thing that comes to mind for me is SQL CLR. MAPI is not specifically supported in .net (at least to my knowledge), although there are work arounds.
    Reading from an exchange mailbox, luckily, is supported in host of situations.

    BTW,I’ve found working with email in .net to be relatively pain free.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an old SQL Server 2000 database that I want to get into
I have been given the enviable task of migrating a legacy SQL Server 2000
We have been using Microsoft Enterprise Lib for data access, some old legacy code
I have SQL server running on a legacy Windows 2003 box on IP address
I have a stored procedure in an old SQL 2000 database that takes a
Scenario: old legacy code in rpg have to consume data from a new web
DirectDraw 7 is very old APIs but we have a lot legacy code written
I have old code that uses size_t which IIRC comes from cstring.h. On OS
We have a lot of old legacy Perl scripts that connect to a MS
I have a Rails application that has to co-exist with a very old legacy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.