Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using Xp_sendmail With the Recipients Generated From a Query


Using Xp_sendmail With the Recipients Generated From a Query

Author
Message
Blasphemy
Blasphemy
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 1
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/kdas/xp_sendmail.asp



bograham
bograham
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
I had been looking for an article like this. Thank you. I still have the problem that sql2000 doesn't seem to like to send through Outlook express for instance. Is there a workaround for this or another very minimal other mail client that might work or is there a way to send straight to smtp server? Could there be a followup article about connecting the entire thing together?

Thanks, Bo



David.Poole
David.Poole
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4387 Visits: 3175
Here is the same thing avoiding CURSORs.

Use Test
GO
Declare @MyRecipients nvarchar (255)
Declare @MyMessage nvarchar (255)
Set @MyRecipients=''
Set @MyMessage = ‘Your timesheet is overdue, please send it ASAP.'
WHILE @MyRecipients IS NOT NULL
BEGIN
SELECT @MyRecipients = MIN ( email_address )
FROM Test_Table
WHERE enail_Address > @MyRecipients AND Status = 0

IF @MyRecipients IS NOT NULL
BEGIN
Print @MyRecipients
Exec Master.dbo.xp_sendmail @MyRecipients, @MyMessage
END
END

LinkedIn Profile

Newbie on www.simple-talk.com
Blasphemy
Blasphemy
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 1
Thx for that code David, I might actually change mine Wink...I wanted to avoid cursors, but it was the first thing I could think of..bad habits die hard...

As to Bo's question, I read an article, I can't quite remember where, but someone had an article posted on how to use Outlook Express and Third Party mailers with xp_Sendmail..I'll see if I can find it.

Real Programmers don't comment their code. If it was hard to write it should be hard to understand.



dwacon
dwacon
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 1
Very good information. I have done this before but never quite so eloquently.



====================
"Awful tired now, Boss. Dog tired."
http://www.dwacon.com


====================
"Awful tired now, Boss. Dog tired."
http://www.dwacon.com

rbenemer
rbenemer
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
An excellent tip

Rex


Rex
jamyer
jamyer
SSC-Enthusiastic
SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)SSC-Enthusiastic (177 reputation)

Group: General Forum Members
Points: 177 Visits: 16
What about when the email name you are retrieving from a table is no longer valid? Any ideas on error processing?

Can't quite get this part to work properly, or it works okay until the 1st illegal name is encountered then "rolls back". Then retries x number of times (something you define) and then sends the emails out again until that first illegal address is encountered. Wish xp_sendmail had error processing and was documented better.

To make a long story short, if you try to process email addresses in a table within a proc, it can't roll back xp_sendmail operations and if you have set retry option up then you get duplicate emails sent to some humorless people!



Jason Delaune
Jason Delaune
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1293 Visits: 11
I used the same code that's in the article for a recent project, and it works great. However, I noticed in the code that the first recipient will not receive the email.

1. This is because after you fetch their email address, you then check the FETCH_STATUS to make sure it's valid.
2. You then print the email address and fetch a new one.
3. Then the email is sent.

It seems that you would want to send the email before fetching the next record. Otherwise, someone will be left out.

Jason



vijay_kumar
vijay_kumar
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 1
Good thought provoking article, got some new ideas on e-mail and cursors.



Connie Miner
Connie Miner
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 1
Do you have to have SQL Mail set up to use xp_sendmail?



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search