【发布时间】:2018-04-27 09:53:19
【问题描述】:
我已按照教程使用提醒和日历约会发送自动电子邮件。
“基地”来自https://www.extendoffice.com/documents/outlook/1567-outlook-send-schedule-recurring-email.html
问题在于签名中的图像变成了 html 标签。
Ron de Bruin 的代码在这里:https://www.rondebruin.nl/win/s1/outlook/signature.htm 可以在 html 中添加签名,它几乎可以工作。
我得到正确的文本、字体、颜色和链接,但图像是带有红色 x 的空框。
我查看了消息的来源,似乎签名的代码抓取了硬编码的相对 img 来源。
所以我尝试添加“替换”代码以将消息中的源编辑为绝对路径。
它奏效了!但只在我的电脑上。
图像没有添加,它们只是链接到。
任何有解决方案的人如何添加(或附加)图像以使签名看起来正确?
Private Sub Application_Reminder(ByVal item As Object)
Dim MItem As MailItem
Set MItem = Application.CreateItem(olMailItem)
If item.MessageClass <> "IPM.Appointment" Then
Exit Sub
End If
If item.Categories <> "Beställa material mail" Then ' make sure it's correct category
Exit Sub
End If
If Now > item.End + 6 / 24 Then ' if the appointment time was when computer was off (or long delay) don't email.
MsgBox item.Subject & " är inte skickat för att det är för sent." ' "subject" is not send because it's too late.
Exit Sub
End If
'Below is from https://www.rondebruin.nl/win/s1/outlook/signature.htm
SigString = Environ("appdata") & "\Microsoft\Signatures\Axfood.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
'replace incorrect img sources.
Signature = Replace(Signature, "src=" & Chr(34) & "Axfood-filer/image", "src=" & Chr(34) & Environ("appdata") & "/Microsoft/Signatures/Axfood-filer/image")
' send email
MItem.To = item.Location
MItem.Subject = item.Subject
MItem.HTMLBody = item.Body & Signature
MItem.Send
Set MItem = Nothing
End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
编辑;
Outlook 签名文件中的示例 img 源:<img border=0 width=21 height=21
src="Axfood-filer/image010.jpg" v:shapes="_x0000_i1030">
这是使用代码中的替换功能编辑到硬盘驱动器上的绝对路径。
签名文件可以在:C:\Users\<USER>\AppData\Roaming\Microsoft\Signatures
【问题讨论】:
-
显示实际的 HTML。它必须有
<img src="http(s)://pathtoserver.com/pathtoimage/image.jpg" />还需要适当的 HTML mime 标头 -
就是这样。它不是“http”,Outlook 将图像保存在本地,而 HTML 具有本地地址。这是来自 HTML 的图像之一:
<img border=0 width=21 height=21 src="Axfood-filer/image010.jpg" v:shapes="_x0000_i1030"> -
如果你在文本中添加
<img src="https://via.placeholder.com/350x150" />? -
如果我这样做,我会在源代码中得到这个:
<img border=0 width=21 height=21 src="https://via.placeholder.com/350x150010.jpg" v:shapes="_x0000_i1030">但图像不会显示。不在计算机或我的 Android 手机上。 -
对不起...我明白了我的错误。
10仍然在链接中。给我一分钟,我会再试一次。