1
我有一些VBScript發送電子郵件。但是當我嘗試發送Unicode文本時,結果是不可讀的。我嘗試了一些像.Charset="UTf-8"
但它是絕望的。我的VBScript代碼如下所示; emailbody.txt文件包含這樣的內容「hưđiềuhànhkhởiđộng!」如何使用VBScript發送帶有Unicode字符的電子郵件?
Option Explicit
Call Email
Function Email
Dim iMsg, iConf, Flds, schema
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = ""
Flds.Item(schema & "sendpassword") = ""
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
'These constants are defined to make the code more readable
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, BodyText, HeadText
Set fso = CreateObject("Scripting.FileSystemObject")
'Open the file for reading
Set f = fso.OpenTextFile("emailbody.txt", ForReading) 'edit path if required
'The ReadAll method reads the entire file into the variable BodyText
BodyText = f.ReadAll
'Close the file
f.Close
Set f = Nothing
Set fso = Nothing
With iMsg
.To = ""
.From = ""
.Sender = ""
.Subject = ""
.HTMLBody = BodyText
Set .Configuration = iConf
.Send
End With
set iMsg = nothing
set iConf = nothing
set Flds = nothing
End Function
['OpenTextFile'](http://msdn.microsoft.com/en-us/library/314cz14s( v = vs.85).aspx)的第4個參數允許你閱讀Unicode文件 – 2011-08-29 22:42:10
感謝文檔 – Ryo