VBScriptで「CDO.Message」を利用し、お手軽にメール送信する方法。
これで、バッチエラーなどの場合にアラートメールを送信することができる。
実際にやってみた。
下記のようにして、「Gmailアカウント」を使用してメール送信できた。
Set objMail = CreateObject("CDO.Message")
objMail.From = "送信元メールアドレス(xxxxx@gmail.com)"
objMail.To = "送信先メールアドレス(xxxxx@gmail.com)"
objMail.Subject = "件名:メール送信テスト"
objMail.TextBody = "本文:これはメール送信テストです。"
strConfigurationField ="http://schemas.microsoft.com/cdo/configuration/"
With objMail.Configuration.Fields
.Item(strConfigurationField & "sendusing") = 2
.Item(strConfigurationField & "smtpserver") = "smtp.googlemail.com"
.Item(strConfigurationField & "smtpserverport") = 465
.Item(strConfigurationField & "smtpusessl") = true
.Item(strConfigurationField & "smtpauthenticate") = 1
.Item(strConfigurationField & "sendusername") = "Gmailアカウント(xxxxx@gmail.com)"
.Item(strConfigurationField & "sendpassword") = "パスワード"
.Item(strConfigurationField & "smtpconnectiontimeout") = 60
.Update
end With
objMail.Send
Set objMail = Nothing
なお、設定値は以下のようです。
- sendusing…2(SMTPを使用するので固定らしい)
- smtpusessl…true/false(SSL通信をする/しない)
- smtpauthenticate…1/2(Basic認証/NTLM認証)
- smtpconnectiontimeout…接続タイムアウト秒数


コメント