Oracle Consulting Oracle Training Oracle Support Development
Oracle Books
SQL Server Books
IT Books
Job Interview Books
Rampant Horse Books
911 Series
Pedagogue Books

Oracle Software
Write for Rampant
Publish with Rampant
Rampant News
Rampant Authors
Rampant Staff
Oracle News
Oracle Forum
Oracle Tips
Articles by our Authors
Press Releases
SQL Server Books

Oracle 11g Books

Oracle tuning

Oracle training

Oracle support

Remote Oracle


Privacy Policy


  SQL Server Tips by Burleson

Applications of XP_SMTPSENDMAIL

One interesting application of XP_SMTPSENDMAIL is to get email addresses from a table and send an email to all of them. The sample databases Northwind and Pubs have several tables with contact information for employees, customers, etc. but, surprisingly, none has an email field. It really does not matter because we need real email addresses to send the emails, in case this code is used to test the XP, and verifying that they reached their destination. For testing purposes we will create a table named EmployeeInfo, with only one field named email:

CREATE TABLE EmployeeInfo(email varchar(50))

The table will get three records (these email addresses should be replaced with valid ones, even one email will do for the test):

INSERT EmployeeInfo(email) VALUES('')
INSERT EmployeeInfo(email) VALUES('')
INSERT EmployeeInfo(email) VALUES('')

Finally, a cursor will read the email address field from the table and feed it into XP_SMTPSENDMAIL:

SELECT email FROM EmployeeInfo
OPEN cur_email
FETCH NEXT FROM cur_email INTO @email
EXEC master..XP_SMTPSENDMAIL @From='',
@To=@email, @Subject='Friday meeting',
@Body='Meeting has been cancelled.'
FETCH NEXT FROM cur_email INTO @email
CLOSE cur_email
DEALLOCATE cur_email

This example, for minimalism, assumes that the sender, body and subject will be the same for all the emails. They could be taken from the table itself or from other source.

The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter  

Linux Oracle commands syntax poster

ION Oracle tuning software

Oracle data dictionary reference poster

Oracle Forum

BC Oracle consulting support training

BC remote Oracle DBA   



 Copyright © 1996 -2017 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation. SQL Server® is the registered trademark of Microsoft Corporation. 
Many of the designations used by computer vendors to distinguish their products are claimed as Trademarks

Hit Counter