xp_readmail is for SQL Mail
, which is deprecated.
In my opinion this kind of work should be done way far away from the database engine. There are many applications out there that will monitor an inbox (IMAP, Exchange, POP3, etc.) and allow you to react to new messages as they arrive, or shortly thereafter.
i played around and created a CLR which reads the emails off of a POP3 server as a proof of concept; like every email application I've ever fiddled with, it can be slow. expecting results in 30 seconds just plain woun't happen unless you delete everything you pick up off of the server.
for example, when it picks up my personal email box, it finds out there are 407 available messages; because I added a parameter, and so when it downloaded the most recent x number of messages (54 messages in one example, 25 in another) , it took 47 seconds and 31 seconds respectively.
if it was still getting the whole 407 emails, i would recon it would take on the order of 400 to 600 seconds at least
, assuming the mail server doesn't hiccup
Ok There's an advantage if you love TSQL since I have the results in a Table Value function so i could fiddle with the results from there...but it would require parsing the body and all sorts of other rules and stuff that hits on the point opc.three chimed in on...there's better tools that SQL to be doing this. it'd be a whole 'nuther level of headache trying to handle attachments, which are potentially one-to-many for each email message.
it's moderately difficult and took me a while to get the prototype to work, and I think i'll throw an article up for it, since it's an often-asked but rarely example kind of question. the caveats and problems
the body ends up like this in an nvarchar(max) field:
Hi Lowell,=0D=0A=0D=0AA new reply has been added by Steve Jones - SSC Editor= to a topic you're subscribed to.=0D=0A=0D=0AYou can view the reply by clicking= the link below...=0D=0A=0D=0Ahttp://www.sqlservercentral.com/Forums/FindPost1398664.aspx= =0D=0A=0D=0AYou can unsubscribe from topics at anytime from your control= or the following link...=0D=0A=0D=0Ahttp://www.sqlservercentral.com/Forums/TopicSubscriptions1.aspx= =0D=0A=0D=0AYou may need to manually copy & paste the URL into the address= bar of your browser if the text above is not linked. Please watch for the= URL wrapping onto 2 lines. =0D=0A=0D=0A-----------------------------------------= =0D=0A=0D=0ASQLServerCentral=0D=0Ahttp://www.sqlservercentral.com/Forums/= =0D=0A
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!