1

下面的 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\myemail@harryLLC.com_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>myemail@HarryLLC.com</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 = 
 'myemail@harryLLC.com',
    @recipients = 'myemail@harryLLC.com',
    @subject = 'The DBMail answer with logo insertion', 
    @Body =  @MsgBody   ,
     --all of the following are optional
    @file_attachments= @Attachments 
    --, @reply_to = 'myemail@harryLLC.com'
    ,@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 代码使用上面更简单的 HTML 调用 msdb.dbo.sp_send_dbmail 时,我无法让 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, "myemail@harryLLC.com")
  ObjCommand.Parameters.Append ObjCommand.CreateParameter("@Body_format", adVarChar, adParamInput, 5, "HTML")
  ObjCommand.Parameters.Append ObjCommand.CreateParameter("@recipients", adVarChar, adParamInput, 200, "myemail@harryLLC.com")
  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\myemail@harryLLC.com_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
4

1 回答 1

1

在微软做过的所有最愚蠢的事情中,如果不是大奖得主,这件事情就排在前五名! OUTLOOK对我消息中的HTML区分大小写!我注意到在我使用 cid:image001.png 的 SQL 脚本和 VB6 代码中我有 CID .....现在我正在抓住稻草,所以我说好吧,让我们看看是不是这样...... ..它是

于 2018-06-19T20:43:30.187 回答