Windowsスクリプトでメール送信する方法 
2013/07/18 Thu.
遠隔地にあるパソコンをWOLで起動するようにしているが、しばしば勝手に立ち上がっていることがある。
(´・ω・`)・ω・`) キャー
/ つ⊂ \ 怖いー
ということで、気がついたときに遠隔操作で電源を落とすのですが、立ち上がったことを知る方法がないかな?と考えた結果、ウィンドウズが立ち上がったときにメールを送ってくるようにすることに。
しかし、どうやって実現しよう。
と思ったら、ウィンドウズには便利なスクリプトが用意されていた。
Windows Script Host (ウインドウズ・スクリプト・ホスト)というやつです。
これの詳細はほかに譲るとして、これでメール送信をするサンプルを備忘録。
(´・ω・`)・ω・`) キャー
/ つ⊂ \ 怖いー
ということで、気がついたときに遠隔操作で電源を落とすのですが、立ち上がったことを知る方法がないかな?と考えた結果、ウィンドウズが立ち上がったときにメールを送ってくるようにすることに。
しかし、どうやって実現しよう。
と思ったら、ウィンドウズには便利なスクリプトが用意されていた。
Windows Script Host (ウインドウズ・スクリプト・ホスト)というやつです。
これの詳細はほかに譲るとして、これでメール送信をするサンプルを備忘録。
※赤文字のところは必要に応じて変更してください。
●GMAILの送信サーバーを利用する方法
Set objMail = CreateObject("CDO.Message")
objMail.From = "abcdef@gmail.com"
objMail.To = "送信先@abc.com"
objMail.Subject = "GMAIL SSL通信によるSMTP認証メール送信テスト"
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") = "abcdef@gmail.com"
.Item(strConfigurationField & "sendpassword") = "Password"
.Item(strConfigurationField & "smtpconnectiontimeout") = 30
.Update
end With
objMail.Send
Set objMail = Nothing
●Yahooの送信サーバーを利用する方法
Set objMail = CreateObject("CDO.Message")
objMail.From = "abcdef@yahoo.co.jp"
objMail.To = "送信先@abc.com"
objMail.Subject = "Yahoo SMTP認証メール送信テスト"
objMail.TextBody = "とーどーいーたー"
strConfigurationField ="http://schemas.microsoft.com/cdo/configuration/"
With objMail.Configuration.Fields
.Item(strConfigurationField & "sendusing") = 2
.Item(strConfigurationField & "smtpserver") = "smtp.mail.yahoo.co.jp"
.Item(strConfigurationField & "smtpserverport") = 587
.Item(strConfigurationField & "smtpusessl") = False
.Item(strConfigurationField & "smtpauthenticate") = 1
.Item(strConfigurationField & "sendusername") = "YahooID"
.Item(strConfigurationField & "sendpassword") = "Password"
.Item(strConfigurationField & "smtpconnectiontimeout") = 30
.Update
end With
objMail.Send
Set objMail = Nothing
※YahooはSSLでうまくいかなかったのでSSLにしていません。
●GMAILの送信サーバーを利用する方法
Set objMail = CreateObject("CDO.Message")
objMail.From = "abcdef@gmail.com"
objMail.To = "送信先@abc.com"
objMail.Subject = "GMAIL SSL通信によるSMTP認証メール送信テスト"
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") = "abcdef@gmail.com"
.Item(strConfigurationField & "sendpassword") = "Password"
.Item(strConfigurationField & "smtpconnectiontimeout") = 30
.Update
end With
objMail.Send
Set objMail = Nothing
●Yahooの送信サーバーを利用する方法
Set objMail = CreateObject("CDO.Message")
objMail.From = "abcdef@yahoo.co.jp"
objMail.To = "送信先@abc.com"
objMail.Subject = "Yahoo SMTP認証メール送信テスト"
objMail.TextBody = "とーどーいーたー"
strConfigurationField ="http://schemas.microsoft.com/cdo/configuration/"
With objMail.Configuration.Fields
.Item(strConfigurationField & "sendusing") = 2
.Item(strConfigurationField & "smtpserver") = "smtp.mail.yahoo.co.jp"
.Item(strConfigurationField & "smtpserverport") = 587
.Item(strConfigurationField & "smtpusessl") = False
.Item(strConfigurationField & "smtpauthenticate") = 1
.Item(strConfigurationField & "sendusername") = "YahooID"
.Item(strConfigurationField & "sendpassword") = "Password"
.Item(strConfigurationField & "smtpconnectiontimeout") = 30
.Update
end With
objMail.Send
Set objMail = Nothing
※YahooはSSLでうまくいかなかったのでSSLにしていません。
- 関連記事
category: パソコン
この記事へのコメント
コメントの投稿
コメントは全て管理人が内容を確認してから表示されます(非公開コメント除く)。
内容によっては表示されない場合がありますことご了承願います。
内容によっては表示されない場合がありますことご了承願います。
« Avast antivirus と COMODO Firewall の組み合わせ
東芝が世界最速のUHS-Ⅱ対応SDHCメモリカード「エクセリア」を出すみたい »