Email via SMTP from Batch File

I would like to use a batch file to send an email via a SMTP mail server with attachments.

I have all the settings because I use the SMTP within my SQL server.  The purpose of this  batch file is to take a 'txt' file and forward it to a recipient.  One other wrinkle is that it has to be conditional based on the value within a file, Y or N.

Is this possible?

Thanks

Glen
GPSPOWAsked:
Who is Participating?
 
Jon JaquesInformation TechnologistCommented:
Hello,

Yes, this is doable with PowerShell; Here is the docs for the Send-MailMessage command:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-5.1 .

Powershell also has the ability to read inside of the file and work with the contents. How difficult that is depends on how burried within the file your conditional value is, and some other factors. Using this method, you could create a simple batch file which you double-could click on, and would conditionally email the attachment file. You could also run the file periodically/automatically using Scheduler or some other trigger, possibly within SQL server.

--Jon
0
 
GPSPOWAuthor Commented:
Let me try my powershell application.

I'll let you know.

Thanks

Glen
0
 
GPSPOWAuthor Commented:
Using the attached link and other reference articles I was able to accomplish my task of  setting up a conditional test and then emailing an attachment I created from one of my SQL scripts.

Thanks

Glen
1
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Jon JaquesInformation TechnologistCommented:
Great, glad that worked for you!

Sometimes I love PowerShell, it can really make tasks easy.

Take care,

Jon
0
 
GPSPOWAuthor Commented:
Please close question.
See my comments above.
0
 
Jon JaquesInformation TechnologistCommented:
Hello, isn't there a button to accept my answer as a solution?
0
 
GPSPOWAuthor Commented:
I just check it as helpful.

I do not see any other buttons.

Thanks

Glen
0
 
Jon JaquesInformation TechnologistCommented:
Glad to help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.