VB6 vs SQL 脚本 DBMail 到 outlook,出了什么问题?



以下 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-hostthe-share- 
namemyemail@harryLLC.com_filesimage001.png'
--set @Attachments = @Attachments + ';\the-SQL-servers-hostthe-share- 
namethe 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-hostthesharemyemail@harryLLC.com_filesimage001.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

在Microsoft做过的所有最愚蠢的事情中,如果不是大奖得主,这个也是前五名!OUTLOOK对我的邮件中的HTML区分大小写!我注意到在SQL脚本中我使用了cid:image001.png而在VB6代码中我有CID.....现在在这一点上,我抓住了吸管,所以我说好吧,让我们看看是不是这样......原来如此

最新更新