我使用以下代码发送自动电子邮件,并在其中传递参数:
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 2
Const cdoSendUsingPort = 2
Dim oMsg, oConf
Dim sDateTimeStamp
Set args = WScript.Arguments
arg1 = args.Item(0)
' E-mail properties
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "test@gmail.com" ' or "Sender Name <from@gmail.com>"
oMsg.To = "test2@gmail.com" ' or "Recipient Name <to@gmail.com>"
oMsg.Subject = "Subject"
oMsg.TextBody = "Transfer of files failed - Check RUNLOG for error. Julian date : " & arg1
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp server" 'server address
oConf.Fields(schema & "smtpserverport") = 25 'port number
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic 'authentication type
oConf.Fields(schema & "smtpusessl") = False 'use SSL encryption
oConf.Fields(schema & "sendusername") = "test3@gmail.com" 'sender username
oConf.Fields(schema & "sendpassword") = "password" 'sender password
oConf.Fields.Update()
我想在短信主体中添加一个多行字符串,我尝试过使用_ concat运算符,如下所示:
multi = "aaaaaa " & _
"FROM NC301B " & _
"WHERE EDIPROC like 'P30_' " & _
"AND (LF301M > 0) "
但它不起作用。有人可以给我指点吗?谢谢。
我希望电子邮件的结尾处包含以下内容:
"Transfer of files failed - Check RUNLOG for error."
"Julian date : " & arg1
"Line of text"
"Line of text"
如果没有& _
的多层次,这也是可行的,那么我也很好奇。谢谢!
答案 0 :(得分:2)
只是添加字符串连接字符并不自动插入换行符,您需要使用其中一个内置常量来定义换行符
multi = "aaaaaa " & vbNewLine & _
"FROM NC301B " & vbNewLine & _
"WHERE EDIPROC like 'P30_' " & vbNewLine & _
"AND (LF301M > 0) "
vbNewLine
是最好的,因为它是特定于平台的。但为了完整性,其他的是;
'--- Named Constants ---
vbCr 'Carriage Return
vbLf 'Linefeed
vbCrLf 'Carriage Return Linefeed
'--- Character Codes using Chr() ---
Chr(13) 'Carriage Return
Chr(10) 'Linefeed
Chr(13) & Chr(10) 'Carriage Return Linefeed
如果您还想使用换行符为您的电子邮件构建HTMLBody
,则无法使用HTML忽略空格,您需要使用<br />
来强制换行。