【问题标题】:Outlook 2010 VBA script to retain <head></head> section of a .html importOutlook 2010 VBA 脚本保留 .html 导入的 <head></head> 部分
【发布时间】:2015-01-13 02:48:30
【问题描述】:

提前致谢。 我一直在研究允许使用 VBA 将 html 代码或 .html 文件导入到 Outlook 2010 电子邮件中的各种方法,但令我沮丧的是,我注意到所有导入技术似乎都会导致 HEAD 中包含的所有样式元素被剥离。

例如,当使用具有相同 html CSS 代码的 Thunderbird 时,它可以完美地工作,并且在发送收件人时,尽管有客户端(gmail、yahoo 等),但似乎也能获得样式。 Thunderbird 通过一个简单的 HTML 输入就能完美地完成这项工作。那么,为什么我要尝试通过 Outlook 来实现这一目标呢?简单来说就是客户想用outlook 2010。

我很难相信没有一些漂亮的工作可以防止 Outlook 删除此内容,然后在发送电子邮件时保留 HEAD 内容,以便响应式样式正常工作。

这是我目前一直在使用的

VBA 参考

  • Visual Basic 应用程序
  • Microsoft Outlook 14.0 对象库
  • Microsoft Office 14.0 对象库
  • Microsoft Word 14.0 对象库
  • OLE 自动化

被剥离的代码

<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />

<style type="text/css">

body{width:100%;margin:0px;padding:0px;background:#444444;text-align:center;}
html{width: 100%; }
img {border:0px;text-decoration:none;display:block; outline:none;}
a,a:hover{color:#ee7716;text-decoration:none;}.ReadMsgBody{width: 100%; background-color: #ffffff;}.ExternalClass{width: 100%; background-color: #ffffff;}
table {border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; } 
.padtop10 {padding-top:10px;}
.main-bg{ background:#444444;}
.pads {padding:0px 15px 0px 15px;}
.mobdes{font-size:10px;}
@media only screen and (max-width:640px)

{
    body{width:auto!important;}
    .padtop10 {padding-top:0px;}
    .main{width:100% !important;margin:0px; padding:0px;}
    .two-column{width:100% !important;margin:0px; padding:0px;}
    .mobileCenter{width: 100% !important; text-align: center!important;}
    .two-left{width: 100% !important; text-align: center!important;}
    .date{font:Bold 14px Arial, Helvetica, sans-serif; color:#ee7716;}
    .mobdes{font-size:8px !important;}
    .customobpad{padding-top:30px !important;}

}

@media only screen and (max-width:479px)
{
    body{width:auto!important;}
    .padtop10 {padding-top:15px;}
    .main{width:100% !important;margin:0px; padding:0px;}
    .two-column{width:100% !important;margin:0px; padding:0px;}
    .mobileCenter{width: 100% !important; text-align: center!important;}
    .two-left{width: 100% !important; text-align: center!important;}
    .date{font:Bold 12px Arial, Helvetica, sans-serif; color:#ee7716;}
    .mobilogo {height:49px; width:190px !important; padding-left:15px !important; margin-left:-15px;}
    .pads {padding:0px 18px 0px 28px;}
    .mobdes{font-size:8px !important;}
    .customobpad{padding-top:30px !important;}
}
@media only screen and (max-width:800px)
and (orientation : landscape) {
body{width:auto!important;}
    .padtop10 {padding-top:5px;}
    .main{width:100% !important;margin:0px; padding:0px;}
    .two-column{width:100% !important;margin:0px; padding:0px;}
    .mobileCenter{width: 100% !important; text-align: center!important;}
    .two-left{width: 100% !important; text-align: center!important;}
    .date{font:Bold 12px Arial, Helvetica, sans-serif; color:#ee7716;}
    .mobilogo {height:39px; width:172px; padding-left:15px !important; margin-left:-15px;}
    .pads {padding:0px 18px 0px 28px;}
    .mobdes{font-size:8px !important;}
    .customobpad{padding-top:30px !important;}
}



</style>

</head>

用于导入的 VBA 宏代码

Sub InsertHTMLClean2()
Dim insp As Inspector
Set insp = ActiveInspector
If insp.IsWordMail Then
Dim wordDoc As Word.Document
Set wordDoc = insp.WordEditor
Dim FileToOpen As String
FileToOpen = InputBox("filename?")
wordDoc.Application.Selection.InsertFile FileToOpen, , False, False, False
End If
End Sub

我很欣赏许多开发人员说 Outlook 2010 无法保留头部信息,但我想知道是否有人找到了可行的解决方案。我主要对保留 MEDIA QUERIES CSS 感兴趣,因为在当前状态下,移动样式正在破坏。没有关于如何在 Outlook html 电子邮件中重新训练媒体查询 CSS 样式的任何建议。

再次感谢。

【问题讨论】:

    标签: css vba import outlook media-queries


    【解决方案1】:

    您可能知道 Outlook 使用 Word 作为电子邮件编辑器。这就是为什么您会看到 Thuderbird 和 Outlook 之间的差异。以下系列文章提供了与受支持和不受支持的 HTML 元素、属性和级联样式表属性相关的参考文档。

    【讨论】:

    • 感谢您的参考。所以基本上 Outlook 对媒体查询的支持为 0,并且媒体查询不能以任何方式插入,无论是通过强制 VBA 还是通过任何其他方式?微软的所有荣耀!有没有人制作软件或提出解决方案来制作基于 Outlook 的响应式时事通讯?表格单元格百分比将是我的下一个猜测。多么糟糕的软件。再次感谢开发参考表
    猜你喜欢
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    • 2017-07-18
    • 2015-07-30
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    相关资源
    最近更新 更多