To send an email with attachments stored in a database field, use the following code in events like BeforeAdd/AfterAdd/BeforeEdit/AfterEdit.
Make sure to replace "Field that stores attachments" with the actual field name. This must be a TEXT or VARCHAR(max) field that is set up as File/Image in ASPRunnerPro.
Note: Attachments will only work when you selected "Use custom mailer server settings" under "Email settings".
msg =""
set tmpDict = CreateObject("Scripting.Dictionary")
if values("Field that stores attachments")<>"" then
set fileArray = CreateObject("Scripting.Dictionary")
set fileArray = my_json_decode(values("Field that stores attachments"))
set attachments = CreateObject("Scripting.Dictionary")
for i = 0 to asp_count(fileArray)-1
attachments(i) = getabspath(fileArray(i)("name"))
next
set tmpDict("attachments") = attachments
end if
msg = msg & "Make: " & values("Make") & vbcrlf
msg = msg & "Model: " & values("Model") & vbcrlf
tmpDict("to")="test@gmail.com"
tmpDict("subject")="Sample subject"
tmpDict("body")=msg
set ret=runner_mail(tmpDict)
if not ret("mailed") then
response.write ret("message")
end if
See also:
•How to email selected records as separate PDF files
•Send an email to selected users
•Send an email with updated fields only