Skip to content

Instantly share code, notes, and snippets.

@takumin
Created May 14, 2012 09:01
Show Gist options
  • Save takumin/2692860 to your computer and use it in GitHub Desktop.
Save takumin/2692860 to your computer and use it in GitHub Desktop.
function sendmail(from, to, sub, text, server, port, auth, user, pass) {
var obj = WScript.CreateObject("CDO.Message");
var str = "http://schemas.microsoft.com/cdo/configuration/";
obj.Configuration.Fields.Item(str + "sendusing") = 2;
if (typeof(server) != "undefined") {
obj.Configuration.Fields.Item(str + "smtpserver") = server;
}
if (typeof(port) != "undefined") {
obj.Configuration.Fields.Item(str + "smtpserverport") = port;
}
if (typeof(auth) != "undefined") {
obj.Configuration.Fields.Item(str + "smtpauthenticate") = auth;
}
if (typeof(user) != "undefined") {
obj.Configuration.Fields.Item(str + "sendusername") = user;
}
if (typeof(pass) != "undefined") {
obj.Configuration.Fields.Item(str + "sendpassword") = pass;
}
try {
obj.Configuration.Fields.Update();
} catch (e) {
throw e;
}
obj.From = from;
obj.To = to;
obj.Subject = sub;
obj.TextBody = text;
try {
obj.Send();
} catch (e) {
throw e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment