Page 1 of 1

mailto

Posted: 19 Jan 2011 20:50
by scienceguru1.bat
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.

Re: mailto

Posted: 20 Jan 2011 12:46
by aGerman
There is no native command in batch. 2 days before somebody had a similar question.

Regards
aGerman

Re: mailto

Posted: 20 Jan 2011 14:35
by scienceguru1.bat
i have tried a few programs with no success :(

Re: mailto

Posted: 21 Jan 2011 09:41
by avery_larry
both blat.exe and sendemail.exe are very simple to use. google them to download. Post your command and error messages if you still have problems.

Re: mailto

Posted: 22 Jan 2011 02:11
by amel27
try this sample batch SMTPSend function (JS inside):

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);
}}

Re: mailto

Posted: 23 Jan 2011 16:25
by scienceguru1.bat
SMTP: I just get an error message before the window closes, and I cant copy it because the window immediately closes after the text appears.
BLAT/Sendmail: The configs are too confusing, tried a lot.

If a made a SENDMAIL ASP form, then could you tell me how to fill it out?