mailto
Posted: 19 Jan 2011 20:50
how can i make a batch file that sends an email inculding to, subject, and message at the minimum. any other feilds would also be appreciated.
Code: Select all
@set @x=0 /*
@echo off
::--- start proper batch ---
set SMTPsubj=Test Mail
set SMTPtext=Mail Text
call:SMTPSend "%~f0" smtp.srv.com userFrom@my.com userTo@my.com SMTPsubj SMTPtext
EXIT
:SMTPSend BatchName, SMTP_Server, MailFrom, MailTo, Subject, MailText
SETLOCAL EnableDelayedExpansion
if "!%~2!"=="" (set "SMTPserv=%~2") else set "SMTPserv=!%~2!"
if "!%~3!"=="" (set "SMTPfrom=%~3") else set "SMTPfrom=!%~3!"
if "!%~4!"=="" (set "SMTPto=%~4" ) else set "SMTPto=!%~4!"
if "!%~5!"=="" (set "SMTPsubj=%~5") else set "SMTPsubj=!%~5!"
if "!%~6!"=="" (set "SMTPtext=%~6") else set "SMTPtext=!%~6!"
cscript //nologo /e:jscript "%~1" "SMTPSend('%SMTPserv%','%SMTPfrom%','%SMTPto%','%SMTPsubj%','%SMTPtext%')"
ENDLOCAL
GoTo:EOF
::---- end proper batch ----
*/
eval(WScript.Arguments.Item(0));
// -------------------------
function SMTPSend(Server,From,To,Subj,Text) {
var objEmail = WScript.CreateObject("CDO.Message");
objEmail.From = From;
objEmail.To = To;
objEmail.Subject = Subj;
objEmail.Textbody = Text;
//objEmail.BodyPart.CharSet = "utf-8";
with (objEmail.Configuration.Fields) {
Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2;
Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")=Server;
Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25;
// Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1;
// Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="user";
// Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="pass";
Update();
}
try {objEmail.Send();}
catch(e) {
WScript.Echo("ERR: "+e.number);
WScript.Echo(e.message);
}}