Следующий сценарий TSQL работает как шарм:
declare @result as int
declare @myID as int
declare @sig as varchar(MAX)
declare @MsgBody as varchar(MAX)
declare @Attachments as varchar(MAX)
set @Attachments = '\\the-SQL-servers-host\the-share-
name\[email protected]_files\image001.png'
--set @Attachments = @Attachments + ';\\the-SQL-servers-host\the-share-
name\the Estimate #1002.pdf'
set @sig=
'<BR>
<BR>
<table>
<tr>
<td><img src="CID:image001.png"></td>
<TD><table>
<tr> <td>Harry Abramowski</td></tr>
<tr> <td>Harry Abramowski Services, LLC</td></tr>
<tr><TD>(800)555-1212</TD></tr>
<tr> <td>[email protected]</td></tr>
<tr> <td><A href="https://www.facebook.com/harryLLC/">Facebook</a></td>
</tr>
</table>
</TD>
</tr>
</table>'
set @MsgBody= 'This is my message. there is a signature at the bottom, with
logo. And what follows this sentence is a picture.<br> <img
src="cid:image001.png">'
+ '<BR>Pretty cool, Huh?<br><br>Harry' + @sig
EXEC @result=msdb.dbo.sp_send_dbmail @Body_format=HTML, @profile_name =
'[email protected]',
@recipients = '[email protected]',
@subject = 'The DBMail answer with logo insertion',
@Body = @MsgBody ,
--all of the following are optional
@file_attachments= @Attachments
--, @reply_to = '[email protected]'
,@mailitem_ID = @myID OUTPUT
select items.mailitem_id, items.sent_status, items.sent_date from
msdb.dbo.sysmail_allitems items where items.mailitem_id = @myID
ОДНАКО, когда я использую код VB6 для вызова msdb.dbo.sp_send_dbmail с еще более простым HTML, чем указано выше, я не могу заставить изображение image001.png отображаться внутри сообщения. Он отображается как вложение. Я размышлял над этим в течение двух дней и не могу понять, что Outlook видит по-разному между кодом vb6 и скриптом SQL.
Кто-нибудь из вас, гуру VB6, когда-либо имел дело с DBMail? А вот и подпрограмма, которую я тестирую в VB6 — она доставляет сообщение и файл изображения. он просто не получает представления внутри почтового сообщения, как это делает сценарий.
Private Sub hardcoded()
Dim ObjCommand As New ADODB.Command
ObjCommand.ActiveConnection = objConn
ObjCommand.CommandText = "msdb.dbo.sp_send_dbmail"
ObjCommand.CommandType = adCmdStoredProc
ObjCommand.NamedParameters = True
ObjCommand.Parameters.Append ObjCommand.CreateParameter("@profile_name", adVarChar, adParamInput, 100, "[email protected]")
ObjCommand.Parameters.Append ObjCommand.CreateParameter("@Body_format", adVarChar, adParamInput, 5, "HTML")
ObjCommand.Parameters.Append ObjCommand.CreateParameter("@recipients", adVarChar, adParamInput, 200, "[email protected]")
ObjCommand.Parameters.Append ObjCommand.CreateParameter("@subject", adVarChar, adParamInput, 200, "Hardcoded test")
Dim BodyString As String
BodyString = "This is an inserted image that does not appear in the
attachments list." & _
"<BR>This is it right here => <img width=80 height=80 src=" & Chr(34) &
"CID:image001.png" & Chr(34) & ">"
ObjCommand.Parameters.Append ObjCommand.CreateParameter("@Body", adVarChar, adParamInput, 4000, BodyString)
Dim AttachmentString As String
AttachmentString = "\\the-sql-host\theshare\[email protected]_files\image001.png"
ObjCommand.Parameters.Append
ObjCommand.CreateParameter("@file_attachments", adVarChar, adParamInput, 500, Trim(AttachmentString))
ObjCommand.Parameters.Append ObjCommand.CreateParameter("@mailitem_id", adInteger, adParamOutput)
On Error Resume Next
ObjCommand.Execute
If Err Then
MsgBox Err.Number & ": " & Err.Description
Else
MsgBox "Your mail id is " & ObjCommand("@mailitem_id")
End If
End Sub