Created
February 2, 2012 13:29
-
-
Save neiraza/1723481 to your computer and use it in GitHub Desktop.
WSHで自動メール送信
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------- | |
// JScript(WSH)でメール送信 | |
//------------------------------------------------------------------- | |
// Gmailのアカウントを設定 (★以下を書き換えてください★) | |
var gmail_user = "[email protected]"; // Gmailのメールアドレス | |
var gmail_pass = "fuga"; // Gmailのパスワード | |
//------------------------------------------------------------------- | |
// 送信内容の設定(★以下を書き換えてください★) | |
var msg = WScript.CreateObject("CDO.Message"); | |
msg.From = "[email protected]"; // 自分のメールアドレス | |
msg.To = "[email protected]"; // 送り先のメールアドレス | |
msg.Subject = "爆弾"; // メールの件名 | |
msg.TextBody = "爆弾です。\n繰り返します。爆弾です。\n"; | |
msg.AddAttachment('C:\\tmp_picture\\Winter.jpg'); | |
setGmailConfig(msg, gmail_user, gmail_pass); | |
// 送信 | |
msg.Send(); | |
WScript.Echo("送信しました!!"); | |
//------------------------------------------------------------------- | |
// Gmailで送信のための細かい設定を行う | |
function setGmailConfig(msg, user, pass) { | |
msg.TextBodyPart.Charset = 'ISO-2022-JP'; | |
var setConfig = function (conf_obj) { | |
var uri = 'http://schemas.microsoft.com/cdo/configuration/'; | |
for (var key in conf_obj) { | |
msg.Configuration.Fields.Item(uri + key) = conf_obj[key]; | |
} | |
} | |
setConfig({ | |
'sendusing':2, 'smtpconnectiontimeout':30, | |
'smtpserver': 'smtp.gmail.com', 'smtpserverport': 465, | |
'smtpauthenticate': true, 'smtpusessl': true, | |
'sendusername': user, 'sendpassword': pass | |
}); | |
msg.Configuration.Fields.Update(); | |
} | |
//------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment