【发布时间】:2013-10-29 20:09:11
【问题描述】:
我有一个文本文件:
output.txt:
OPERATING SYSTEM SERVER1 SERVER2
Windows 1.36 4.42
Linux 2.78 5.76
MacOS 3.45 6.39
Ubuntu 4.12 0.00
Android 0.00 3.46
FreePhysicalMemory 30.12 31.65
TotalVisibleMemorySize 48.00 48.00
我想将 Output.txt 的内容作为正文发送到电子邮件中,这样它的格式(对齐方式)就不会改变(如 HTMIL 表格格式): 我正在尝试下面的代码。邮件已发送,但邮件正文一无所获。下面是什么错误?
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim objEmail, i
Set objEmail = CreateObject("CDO.Message")
objEmail.Textbody = myTextBody
objEmail.HTMLBody = myHTMLBody
If IsArray( myAttachment ) Then
For i = 0 To UBound( "c:\output.txt" )
.AddAttachment Replace( "c:\output.txt" ( i ), "" ),"",""
Next
ElseIf myAttachment <> "" Then
.AddAttachment Replace( "c:\output.txt", ""),"",""
End If
objEmail.TO ="sunny@abc.com"
objEmail.From = "dontreply@abc.com (CCP Stored Procedure Message)"
objEmail.Subject = "CCP Stored Procedure"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpb.intra.abc.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration /smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Set objEmail = Nothing
EDIT1
使用以下代码,我收到如下电子邮件..
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f , objCDO1 ,BodyText
Set fso = CreateObject("Scripting.FileSystemObject")
Set objCDO1 = CreateObject("CDO.Message")
BodyText = fso.OpenTextFile("c:\Output.txt",ForReading).ReadAll
BodyText = "<html><body>" + BodyText + "</body></html>"
objCDO1.HTMLBody = BodyText
objCDO1.TO ="sunny@abc.com"
objCDO1.From = "dontreply@bt.com (HFM)"
objCDO1.Subject = "StatS"
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpb.abc.com"
objCDO1.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDO1.Configuration.Fields.Update
objCDO1.Send
Set f = Nothing
Set fso = Nothing
电子邮件
OPERATING SYSTEM SERVER1 SERVER2 Windows 1.36 4.42 Linux 2.78 5.76 MacOS 3.45 6.39 Ubuntu 4.12 0.00 Android 0.00 3.46 FreePhysicalMemory 30.12 31.65 TotalVisibleMemorySize 48.00 48.00
为什么不以 output.txt 格式接收电子邮件?
EDIT2
当我在 EDIT1 中使用下面时..它的工作原理。
BodyText = fso.OpenTextFile("c:\Output.txt",ForReading).ReadAll
objCDO1.HTMLBody = "<html><body><pre>" & BodyText & "</pre></body></html>"
但是..当我在EDIT1中使用下面时..它不起作用。
BodyText = fso.OpenTextFile("c:\Output.txt",ForReading).ReadAll
objCDO1.HTMLBody = "<html><body><font size="12"><pre>" & BodyText & "</pre></font></body></html>"
【问题讨论】:
-
myTextBody和myHTMLBody的值是多少?你的代码中有On Error Resume Next吗?因为.AddAttachment Replace( "c:\output.txt" ( i ), "" ),"",""不可能工作。在架构 URL 中还有不属于sendusing字段的空格。 -
嗨 Ansgar..我改变了方式..!请参阅 EDIT1...:)
-
将
size="12"更改为size='12'或size=""12""。 VBScript 字符串中的双引号必须被转义(通过将它们加倍)。但是,在 HTML 代码中,用单引号替换它们会更简单。 -
@Ansgar..tried ..但我想知道没有 html 字体类型,字体等标签在这里工作..在每种情况下,邮件都是默认的 courier 新字体大小 10 format.should I go for Powershell..?.:)
-
现在我只想在 和 中制作它。
标签: html vbscript html-table html-email