在 MS Access / Outlook 中兑换(尝试在电子邮件中包含单独的消息文件)
Redemption in MS Access / Outlook (trying to include a separate message file in email)
此代码位于 MS Access (2010) VBA 中,使用 Microsoft Outlook 2010 的 Redemption 库。
我以前有这个过程,但我们最近进行了 Citrix 升级,我想我在 Outlook 中重置了一些东西,现在这个过程不再有效。
我有一个 .msg 文件文件夹,这些文件基本上是预制的电子邮件模板,具有所有正确的格式、图像、文本等。
这是我之前做的:
Dim outlookApp As Object, namespace As Object
Dim oItem, MyItem
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_dot_msg_file)
'And then there are many calls like this:
MyItem.HTMLBody = Replace(MyItem.HTMLBody, "Dear Person,", "Dear " & name)
'...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
'this next line displays the email, and as of this line, it looks correct
'safeItem.Display
'but as of this line, the issue occurs
safeItem.HTMLBody = "<p>This is an extra message that shows up before the .msg file</p>" & safeItem.HTMLBody
safeItem.Recipients.ResolveAll
safeItem.Send
现在发送电子邮件时,.msg 内容根本不存在 -- 唯一显示的是我在 HTMLBody 前面添加的 "extra message"。
我需要更改或更新什么?这是我需要在代码或 Outlook 设置等中更改的内容吗?
额外:正文插入:
Function insertStringBodyTag(htmlBody As String, stringToInsert As String)
Dim s As String
Dim i As Integer
s = htmlBody
i = InStr(1, s, "<body")
i = InStr(i, s, ">")
s = Left(s, i) & stringToInsert & Right(s, Len(s) - i)
insertStringBodyTag = s
End Function
'Called with safeItem.htmlBody = insertStringBodyTag(safeItem.htmlBody, prefix_string)
您不能连接 2 个 HTML 字符串并期望返回一个有效的 HTML 字符串 - 必须合并这两个字符串 - 找到 "<body"
子字符串在原始 [=14] 中的位置=] body,然后找到以下 ">"
的位置(这样你就可以处理带有属性的 body 元素),然后在“>”之后插入你的 HTML 字符串。
此代码位于 MS Access (2010) VBA 中,使用 Microsoft Outlook 2010 的 Redemption 库。
我以前有这个过程,但我们最近进行了 Citrix 升级,我想我在 Outlook 中重置了一些东西,现在这个过程不再有效。
我有一个 .msg 文件文件夹,这些文件基本上是预制的电子邮件模板,具有所有正确的格式、图像、文本等。
这是我之前做的:
Dim outlookApp As Object, namespace As Object
Dim oItem, MyItem
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
namespace.Logon
Set MyItem = outlookApp.CreateItemFromTemplate(path_to_dot_msg_file)
'And then there are many calls like this:
MyItem.HTMLBody = Replace(MyItem.HTMLBody, "Dear Person,", "Dear " & name)
'...
Set safeItem = CreateObject("Redemption.SafeMailItem")
Set oItem = MyItem
safeItem.Item = oItem
'this next line displays the email, and as of this line, it looks correct
'safeItem.Display
'but as of this line, the issue occurs
safeItem.HTMLBody = "<p>This is an extra message that shows up before the .msg file</p>" & safeItem.HTMLBody
safeItem.Recipients.ResolveAll
safeItem.Send
现在发送电子邮件时,.msg 内容根本不存在 -- 唯一显示的是我在 HTMLBody 前面添加的 "extra message"。
我需要更改或更新什么?这是我需要在代码或 Outlook 设置等中更改的内容吗?
额外:正文插入:
Function insertStringBodyTag(htmlBody As String, stringToInsert As String)
Dim s As String
Dim i As Integer
s = htmlBody
i = InStr(1, s, "<body")
i = InStr(i, s, ">")
s = Left(s, i) & stringToInsert & Right(s, Len(s) - i)
insertStringBodyTag = s
End Function
'Called with safeItem.htmlBody = insertStringBodyTag(safeItem.htmlBody, prefix_string)
您不能连接 2 个 HTML 字符串并期望返回一个有效的 HTML 字符串 - 必须合并这两个字符串 - 找到 "<body"
子字符串在原始 [=14] 中的位置=] body,然后找到以下 ">"
的位置(这样你就可以处理带有属性的 body 元素),然后在“>”之后插入你的 HTML 字符串。