Is it possible to send a email through Batch file - email

Is it possible to send an email through a batch command line? I have a password batch file for a folder and when you fail three attempts i want it to send me an email. I know its possible to download ans install a program off the internet but when I would open the program it would close. So is there a command or program that sends and email through batch?

TakeCommand will enable all kinds of commandline-magic, including sending of mail. Alkternatively, if you have a local install of PHP (and properly set it up), you could write a PHP-Script to send mail and launch the PHP-Interpreter (in your batch) to execute that file.

Related

conditionally sending cron job emails

I'm not even sure if what I want is possible, but I'd like to run a Cron job where an email is only sent in certain conditions. I know that you can prevent mail from being sent at all by setting MAILTO to an empty string in the crontab file, but I've searched in several different ways, and can't find anything about sending email conditionally. My end goal is to run a Cron job that periodically checks whether the webserver is running, and if not, restart it. I only want an email if the webserver has to be restarted. I'm writing my Cron jobs in Perl. Is there a Perl command I can use within the job script that will disable the email in certain cases? Thanks for any help you can give me.
Cronjobs will send emails if the command you are running generate output. If you write your script to only send output to STDERR/STDOUT when you want an email, that should accomplish your goal.
There are 2 possibilities to send mails from cron jobs:
From program, that has been started by cron daemon,
From UNIX/Linux mechanism, that can send mail, if a program, that has been started as a cron job, has written something to STDOUT or STDERR.
I don't recommend to use the 2nd possibility. It is inflexible. You can't send mails to different recipients, depending on what alert has happened.
Usage of the 2nd way is rather a bad design. Cron jobs should redirect all their stdout and stderr to an idividual for every cron job log file for possible troubleshooting.
Perl possesses perfect possibilities to send mails, e.g. using MIME::Lite module.
This module is not a core one, so that you might should request sysadmin to install this module, if it's not available.
If you will use the 1st way, then your issue is easy to solve using Perl logic: just send the required mail from your Perl program after this program restarted the web server.

PHP mail() in dev environment: open the mail in a browser/editor instead of sending it?

On my machine I need to test the mails sent by my application. I'd rather avoid sending real mails.
Is there a way to have the email content showed to the screen a way or another, maybe by opening it in gedit or any text editor?
Maybe like replacing the commandline used to launch "sendmail"?
I am asking for Linux machines (Ubuntu more specifically).
Include a means of determining your environment in your project, or at least some kind of global variable that holds that information.
Then build an abstract mail interface that either sends real mails if it's running on a production server, but logs them to local files in case it runs on a dev machine / environment. As a logging package, I would recommend Monolog.
This would allow you to design the rest of your application (or at least the mail sending components) in a way that doesn't have to care about the environment.
After searching, here is the solution I came to:
create a script that will fake a smtp server
/usr/local/bin/sendmail-fake:
#!/bin/bash
{
date
echo $#
cat
} >> /var/log/sendmail-fake.log
configure PHP:
php.ini:
sendmail_path = /usr/local/bin/sendmail-fake
In this setup, emails are logged into a file. The script could be modified to open the content into a browser.
More details on the blog post.

windows task scheduler send an e-mail with result

I am trying to send an email from windows task scheduler with Action tab. But How can I include the Last run result in this mail. I am not getting any option along with it. There is an option of attaching the files to the mail. So if an one could help me is there any logs files generated by the task scheduler when a task is being run? if so where can I find the log ?
You might have to redirect the result into a log file.And then send that log as an attachment.
For send as email , there is definitely an attach button.

Mail Not Sending from My Server

I am having issues sending mail from my server, when I type in phpinfo() I get this:
Mail: /var/spool/mail/frank
...
_ENV["MAIL"]: /var/spool/mail/frank
The php file that I'm using the Mail function in is owned by Apache and has 775 permissions. Inside /var/spool/mail there is no apache file, but there is a file for every other user on the box. Do I need to change the php.ini? Or can I add in an apache file (perhaps duplicate the frank file and then rename)?
Any advice can help!
/var/spool/mail is where incoming unread mail is stored. There would be an 'apache' file only if the apache account has received mail.
Have you looked inside the MTA's log (usually /var/log/maillog) to see what's going on? If PHP's properly sending mail, there should be an entry in there for the mail being en-queued and what happened when the MTA (postfix/sendmail/exim/etc...) tries to forward it onwards.

scp command with alert message

I want to get the alert message for every execution of the scp command. If some one access my file using the scp command, that time I have to receive one mail. How can I achieve this. Please help me.
Unless you have administrative control of the server, what you ask is not possible -- Unix filesystems simply don't work that way. You can set your file permissions so that other users can't find or read your files, but there is no way for you, as an unprivileged user, to request email notification upon attempted or successful access attempts, via scp or any other method.
Are you on the server, or client side?
server side: Key-based ssh authentication has the ability to start custom commands when the user log into the system (can by bypassed if the user can change the authorized_keys file). There you can add a hook to send a mail on the login, or start a own sftp server with the desired logging enabled.
The right way to do that is to replace the scp program on the server by your own version (or by a wrapper).