Windows標準機能とWSHを使ってメールを送信する(@IT)
マイクロソフト サポート技術情報 - 193685 [IIS]SMTP を利用してコマンド プロンプトで電子メールを送る(Microsoft)にあるスクリプトを外部のSMTPサーバーを使うように変更すると
'----------------------------------------------------------------------- ' ' Sends email from the local SMTP service using CDONTS objects ' ' Usage: ' sendmail -t-f -s " " -b " " ' sendmail [-help|-?] ' '----------------------------------------------------------------------- '57行目付近でSMTP サーバーを設定 '----------------------------------------------------------------------- Option Explicit 'On Error Resume Next Dim oMsg , oArgs, ArgNum Dim strTo, strFrom, strSubject, strBody Set oMsg = CreateObject("CDO.Message") Set oArgs = Wscript.Arguments ArgNum = 0 While ArgNum < oArgs.Count Select Case LCase(oArgs(ArgNum)) Case "-to","-t": ArgNum = ArgNum + 1 strTo = oArgs(ArgNum) Case "-from","-f": ArgNum = ArgNum + 1 strFrom = oArgs(ArgNum) Case "-subject","-s": ArgNum = ArgNum + 1 strSubject = oArgs(ArgNum) Case "-body","-b": ArgNum = ArgNum + 1 strBody = oArgs(ArgNum) Case "-help","-?": Call DisplayUsage Case Else: Call DisplayUsage End Select ArgNum = ArgNum + 1 Wend If oArgs.Count=0 Or strTo="" Or strFrom="" Or _ strSubject="" Or strBody="" Then Call DisplayUsage Else oMsg.From = strFrom oMsg.To = strTo oMsg.Subject = strSubject oMsg.TextBody = strBody & vbCrLf & Now oMsg.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 oMsg.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _ "mail.example.com" oMsg.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 oMsg.Configuration.Fields.Update oMsg.Send Set oMsg = Nothing End If ' Display the usage for this script Sub DisplayUsage MsgBox ("Usage:" & vbCR &_ " sendmail -t -f -s " &_ Chr(34) & " " & Chr(34) & " -b " & Chr(34) &_ " " & Chr(34) & vbCR &_ " sendmail [-help|-?]" ) WSCript.Quit End Sub
使い方は
sendmail -t KuroYagi@example.com -f ShiroYagi@example.com -s "(# ゜Д゜)" -b "ねぇさん事件です"