Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using xp_readmail to read mail from outer environment Expand / Collapse
Author
Message
Posted Wednesday, January 2, 2013 4:50 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 12:26 AM
Points: 2,840, Visits: 3,963
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
Post #1401776
Posted Wednesday, January 2, 2013 5:14 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, June 12, 2014 2:04 PM
Points: 1,789, Visits: 1,014
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
Post #1401789
Posted Wednesday, January 2, 2013 9:56 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 12, 2014 8:59 PM
Points: 7,124, Visits: 12,652
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
Post #1401938
Posted Wednesday, January 2, 2013 1:47 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:25 AM
Points: 12,914, Visits: 32,071
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1402069
Posted Thursday, January 3, 2013 8:14 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, September 12, 2014 8:59 PM
Points: 7,124, Visits: 12,652
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
Post #1402408
Posted Thursday, January 3, 2013 8:28 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:25 AM
Points: 12,914, Visits: 32,071
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1402413
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse