question

cjfranke avatar image
cjfranke asked

How to send a file from SQL File Table via db mail as an attachment upon creation of the file

  • SQL Server 2016 SP2 on Windows Server 2012.
  • File table (Feedback Forms) is currently in use, files are saved daily by multiple users.
  • Database Mail is configured and was tested successfully.

Scenario:

  1. A training course takes place.
  2. The trainer completes an evaluation form for each student who attended the course.
  3. Trainer emails the evaluation forms to training operations mailbox.
  4. Training Admin forwards the message to another admin (Admin2).
  5. Admin2 saves each evaluation form to a mapped network folder (the file table) using a specific naming convention. (Filename is determined by a query made accessible to admin via Excel.
  6. Admin2 manually emails each evaluation form to the student's manager and copies the local training operations manager.

I would like to automate step 6, and I believe that I can achieve this via a trigger to execute sp_send_dbmail.

I have a view which lists the filename, path_locator and the To and CC email addresses for each file in the database.

I just need some assistance figuring out how to write the trigger to execute sp_send_dbmail with the specifics from the view and attach the PDF file.

triggersql-server-2016dbmailattachment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.