1

I am trying to setup an auto response email from SQL. I have a form that is setup on my CMS which notifies me when a new form has been submitted. The problem is all the emails are coming from a single email address so I can't setup a rule in outlook to auto respond to the user that submitted the form.

I would like to send this email from SQL for every new form that is submitted. I am testing the emails with the code below. I don't know how to dynamically pull the email field from the database field (form_text_box_c0003) to send to each user that submitted the forms...

Any guidance would be much appreciated.


DECLARE @ServerAddr nvarchar(128)
Set @ServerAddr = 'smtp.emailarchitect.net'

DECLARE @From nvarchar(128)
Set @From = 'test@emailarchitect.net'

DECLARE @To nvarchar(1024)
/*You can input multiple recipients and use comma (,) to separate multiple addresses */
Set @To = 'support@emailarchitect.net'

DECLARE @Subject nvarchar(256)
Set @Subject = 'simple email from SQL server'

DECLARE @Bodytext nvarchar(512)
Set @BodyText = 'This is a test text email from MS SQL server, do not reply.'
gunr2171
  • 16,104
  • 25
  • 61
  • 88
MNovak
  • 11
  • 1
  • What SQL server version are you on? My preference is to create an 'email' table that is written to every time you want to send an email. This email table has a trigger on insert that takes the newly entered email_id and feeds it into a stored procedure. Stored procedure accepts that email ID as a variable and reads the email table to get the data required for the email to be sent. Note the XP_sendmail procedure is in the MSDB (hence the reason you need to call a SP) – Twelfth Oct 09 '13 at 17:37
  • I am using SQL 2008 R2. – MNovak Oct 09 '13 at 17:54

0 Answers0