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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.