Send eMail Using Batch File

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Send eMail Using Batch File

Post by jstevens »

Is it possible to send an email using a batch file?

I know how to do it using Excel/VBA: CDO code. I have a number of batch files that I would like an email sent to me once they complete. The batch files reside on a server.

Thanks,
John
Regards,
John

User avatar
StuartR
Administrator
Posts: 12599
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Send eMail Using Batch File

Post by StuartR »

There are a few different methods here
StuartR


User avatar
HansV
Administrator
Posts: 78365
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Send eMail Using Batch File

Post by HansV »

Perhaps you can use Send mail from a batch file. This uses " IIS's SMTP service running on the local machine".

Or try Blat - A Win32 Command Line SMTP Mailer.

(If you have Exchange Server, you can use the mapisend command-line utility from the Exchange Resource Kit)
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Send eMail Using Batch File

Post by jstevens »

Hans,

I used you first link; using "IIS's SMTP service running on the local machine". It worked perfectly as long as the same email address is part of the same domain.

I'm not sure why it is restricted to the same domain but I would like to send an email to my gmail account as well.

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78365
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Send eMail Using Batch File

Post by HansV »

I hope that someone else can help you with this; I don't have any experience with this kind of thing. Sorry...
Best wishes,
Hans

StoneChucker
StarLounger
Posts: 80
Joined: 24 Jan 2010, 13:09
Location: Brantford, Ontario, Canada

Re: Send eMail Using Batch File

Post by StoneChucker »

I've usedSendeMail previously. Very simple command line interface.

Christopher

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Send eMail Using Batch File

Post by jstevens »

Hans,

How would one incorporate more then one email address in the following code? I have tested it but cannot get it to send to more then one email address.

Code: Select all

@echo off & setlocal
:: set the temp file location
set tempmail=%temp%\tempmail.%random%.txt
:: echo the basic headers to the temp file
echo To: "Scripting Test" ^<test@paulsadowski.com^> > %tempmail%
echo From: "Me" ^<me@my.com^> >> %tempmail%
echo Subject: Test2 >> %tempmail%
:: echo the blank line that separates the header from the body text
echo.>>%tempmail%
:: echo the body text to the temp file
echo First line of body text.>> %tempmail%
echo Second line of body text.>> %tempmail%
:: move the temp file to the mail pickup directory
:: adjust this location for your system
move %tempmail% c:\inetpub\mailroot\pickup
set tempmail=
endlocal
Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78365
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Send eMail Using Batch File

Post by HansV »

Have you tried something like

echo To: "John Doe" ^<john.doe@company.com^>, "Mary Lamb" ^<m.lamb@other.com^> > %tempmail%

i.e. separate the recipients with a comma?

BTW, if you don't want to use display names, the e-mail addresses are sufficient:

echo To: john.doe@company.com, m.lamb@other.com > %tempmail%
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2628
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Send eMail Using Batch File

Post by jstevens »

Thank you. I was using a semi-colon.

John
Regards,
John