VBScript メールを送信するサンプル

メールを送信するサンプルです。


Option Explicit

Const useLocalSMTPService = 1
Const useRemoteSMTPService = 2
Const useLocalExchangeService = 3

Dim objMessage
Dim mySMTPServer
Dim mySMTPPort
Dim myAttachment
Dim sendUserName
Dim sendUserPass

mySMTPServer = "SMTPサーバのIPアドレス"
mySMTPPort = ポート番号
myAttachment = "C:\append.txt"   '添付ファイルのファイルパス
sendUserName = "ユーザID"
sendUserPass = "パスワード"

Set objMessage = CreateObject("CDO.Message")
objMessage.From = "送信元メルアド"
objMessage.To = "送信先アドレス"
objMessage.Subject = "件名"
objMessage.TextBody = "本文" & vbCrLf & Now
'objMessage.AddAttachment(myAttachment)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = useRemoteSMTPService
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mySMTPServer
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = mySMTPPort
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = true
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sendUserName
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sendUserPass

objMessage.Configuration.Fields.Update
objMessage.Send

MsgBox "送信完了"


Bookmark this on Yahoo Bookmark
Bookmark this on Google Bookmarks
Share on LinkedIn
LINEで送る
Pocket




コメントはまだありません


You can leave the first : )