VBScriptのCDO.MessageでGmailアカウントを使用したメール送信

VBScript プログラミング
この記事は約3分で読めます。

※当ブログではアフィリエイト広告を利用しています。

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…接続タイムアウト秒数

参考サイト

メモしとこ CDO.Messageによるメール送信

プログラミング
\よかったらシェアしてね!/
えふめん

大阪在住、30代。
業務系SE・社内SE。

PCトラブルの調査、自作デスクトップPCのこと、PC周辺機器のレビューなどの記事を書いています。

えふめんをフォローする
この記事が気に入ったら
いいね!しよう
最新情報をお届けします。

コメント

タイトルとURLをコピーしました