Skip to content

Instantly share code, notes, and snippets.

@stakaya
Created September 24, 2011 10:04
Show Gist options
  • Save stakaya/1239177 to your computer and use it in GitHub Desktop.
Save stakaya/1239177 to your computer and use it in GitHub Desktop.
send by gmail for select folder files.(指定したフォルダの全てのファイルをGメールで送信する)
On Error Resume Next
folder = "" ' フォルダ
from = "" ' 送信元メールアドレス
sendto = "" ' 送信先メールアドレス
user = "" ' ユーザID
pass = "" ' パスワード
Set fso = CreateObject("Scripting.FileSystemObject")
Set src = fso.GetFolder(folder)
For Each FileName In src.Files
Set oMsg = CreateObject("CDO.Message")
url = "http://schemas.microsoft.com/cdo/configuration/"
oMsg.From = from
oMsg.To = sendto
oMsg.Configuration.Fields.Item(url & "sendusing") = 2
oMsg.Configuration.Fields.Item(url & "smtpserver") = "smtp.gmail.com"
oMsg.Configuration.Fields.Item(url & "smtpauthenticate") = 1
oMsg.Configuration.Fields.Item(url & "sendusername") = user
oMsg.Configuration.Fields.Item(url & "sendpassword") = pass
oMsg.Configuration.Fields.Item(url & "smtpserverport") = 465
oMsg.Configuration.Fields.Item(url & "smtpusessl") = True
oMsg.Configuration.Fields.Item(url & "smtpconnectiontimeout") = 60
oMsg.Configuration.Fields.Update
oMsg.Subject = ""
oMsg.TextBody = ""
oMsg.AddAttachment FileName
oMsg.Send
Set oMsg = Nothing
Next
WScript.Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment