Using xp_readmail to read mail from outer environment

  • HI

    Is there any way to read the (Inbox) mails from exchange servers(outside the sql server)? my first requirement is whenever i get any mail ion my mailserver on, lets say "support@abc.com" with subject "master population" then i will get

    notification mail on other email address says "bkumar@abc.com" .

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • I remember doing something very similar in SQL 2000 with xp_readmail ( FAQ email helper - customer emails inbox with subject line HELP and we query the DB for related articles and reply to them links). But I think the correct approach here is to code in .Net or somether programming language , probably create a service which polls the Exchange server and do it that way.

    Jayanth Kurup[/url]

  • 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.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • opc.three (1/2/2013)


    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

    Lowell


    --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!

  • Thanks, Lowell. SQLCLR is a powerful tool, to be sure. You know where I stand on the topic already but I am curious now, can the assembly you created be run as SAFE or does it need EXTERNAL_ACCESS or UNSAFE?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • opc.three (1/3/2013)


    Thanks, Lowell. SQLCLR is a powerful tool, to be sure. You know where I stand on the topic already but I am curious now, can the assembly you created be run as SAFE or does it need EXTERNAL_ACCESS or UNSAFE?

    it required UNSAFE mode , i believe due to the use of System.Net.Sockets and System.Runtime.InteropServices;

    because it piqued my interest, i'm also now fiddling around with adding a CLR that does IMAP also, since that would allow you to find unread items, read specific Folders for new items, etc vs the whole inbox that POP3 limits me to.

    Lowell


    --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!

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply