Guest User

Untitled

a guest
Jun 19th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. declare @result as int
  2. declare @myID as int
  3. declare @sig as varchar(MAX)
  4. declare @MsgBody as varchar(MAX)
  5. declare @Attachments as varchar(MAX)
  6.  
  7. set @Attachments = '\the-SQL-servers-hostthe-share-
  8. namemyemail@harryLLC.com_filesimage001.png'
  9. --set @Attachments = @Attachments + ';\the-SQL-servers-hostthe-share-
  10. namethe Estimate #1002.pdf'
  11.  
  12. set @sig=
  13. '<BR>
  14. <BR>
  15. <table>
  16. <tr>
  17. <td><img src="CID:image001.png"></td>
  18. <TD><table>
  19. <tr> <td>Harry Abramowski</td></tr>
  20. <tr> <td>Harry Abramowski Services, LLC</td></tr>
  21. <tr><TD>(800)555-1212</TD></tr>
  22. <tr> <td>myemail@HarryLLC.com</td></tr>
  23. <tr> <td><A href="https://www.facebook.com/harryLLC/">Facebook</a></td>
  24. </tr>
  25. </table>
  26. </TD>
  27. </tr>
  28. </table>'
  29.  
  30.  
  31. set @MsgBody= 'This is my message. there is a signature at the bottom, with
  32. logo. And what follows this sentence is a picture.<br> <img
  33. src="cid:image001.png">'
  34. + '<BR>Pretty cool, Huh?<br><br>Harry' + @sig
  35.  
  36. EXEC @result=msdb.dbo.sp_send_dbmail @Body_format=HTML, @profile_name =
  37. 'myemail@harryLLC.com',
  38. @recipients = 'myemail@harryLLC.com',
  39. @subject = 'The DBMail answer with logo insertion',
  40. @Body = @MsgBody ,
  41. --all of the following are optional
  42. @file_attachments= @Attachments
  43. --, @reply_to = 'myemail@harryLLC.com'
  44. ,@mailitem_ID = @myID OUTPUT
  45.  
  46. select items.mailitem_id, items.sent_status, items.sent_date from
  47. msdb.dbo.sysmail_allitems items where items.mailitem_id = @myID
  48.  
  49. Private Sub hardcoded()
  50.  
  51. Dim ObjCommand As New ADODB.Command
  52. ObjCommand.ActiveConnection = objConn
  53. ObjCommand.CommandText = "msdb.dbo.sp_send_dbmail"
  54. ObjCommand.CommandType = adCmdStoredProc
  55. ObjCommand.NamedParameters = True
  56. ObjCommand.Parameters.Append ObjCommand.CreateParameter("@profile_name", adVarChar, adParamInput, 100, "myemail@harryLLC.com")
  57. ObjCommand.Parameters.Append ObjCommand.CreateParameter("@Body_format", adVarChar, adParamInput, 5, "HTML")
  58. ObjCommand.Parameters.Append ObjCommand.CreateParameter("@recipients", adVarChar, adParamInput, 200, "myemail@harryLLC.com")
  59. ObjCommand.Parameters.Append ObjCommand.CreateParameter("@subject", adVarChar, adParamInput, 200, "Hardcoded test")
  60.  
  61. Dim BodyString As String
  62. BodyString = "This is an inserted image that does not appear in the
  63. attachments list." & _
  64. "<BR>This is it right here => <img width=80 height=80 src=" & Chr(34) &
  65. "CID:image001.png" & Chr(34) & ">"
  66.  
  67. ObjCommand.Parameters.Append ObjCommand.CreateParameter("@Body", adVarChar, adParamInput, 4000, BodyString)
  68.  
  69. Dim AttachmentString As String
  70. AttachmentString = "\the-sql-hostthesharemyemail@harryLLC.com_filesimage001.png"
  71. ObjCommand.Parameters.Append
  72. ObjCommand.CreateParameter("@file_attachments", adVarChar, adParamInput, 500, Trim(AttachmentString))
  73. ObjCommand.Parameters.Append ObjCommand.CreateParameter("@mailitem_id", adInteger, adParamOutput)
  74. On Error Resume Next
  75. ObjCommand.Execute
  76. If Err Then
  77. MsgBox Err.Number & ": " & Err.Description
  78. Else
  79. MsgBox "Your mail id is " & ObjCommand("@mailitem_id")
  80. End If
  81.  
  82. End Sub
Add Comment
Please, Sign In to add comment