can cron messages display images? - cron

Very simple question - when I run a cron job, everything echoed gets caught and sent to me as a server notification email (not sure exactly what you'd call it). I was wondering if the format for these supports images?
Of course I could just send an email at the end of the cron with my image attached, but I'm curious as to the syntax and format of these server messages.

The output of the cron job is simply packaged up into a mail and sent to the relevant address.
So there's nothing stopping you from (for example) uuencoding an image and pushing that out to standard output, in the right format so that it shows up as an attachment at the destination.

Related

airflow : wait to receive email and process data contained in attached file

I am looking for a wait to schedule tasks based on the reception of an email.
More precisely, I received an email with some attached data every week and I need to add these data into a database (and process some information). Is there a way to do it automatically?
Would airflow be a good option to do this? I found that airflow can send email but I did not find anything about reading mails.
I know it is possible to read email and download attached file in python. But what would be the best way to check if a specific email is received (defined by a sender) and process its data as soon as it is received ?
Airflow is a great option for this workflow.
Airflow has the concept of SensorOperators which are derived from the BaseSensorOperator. Using a SensorOperator will allow you to easily control the poke_interval and timeout of the task as well as how to handle the various situations depending on whether or not the email arrives as expected.
You could schedule some BashOperator or PythonOperator that periodically checks new mail and if they find one they start processing it. While I cannot give you any specific library, I am sure there must be a way to read and handle email in Python.

Check whether cronjob has ran or not

I have one python script running in crontab, I want to check if it is running successfully or not? if not then send mail or another kind of notification. How do I notify based on Cron logs?
Things I already Tried:
All the Exception in python file I have already handled
Need: Notify user if Cron job is not running successfully?
In order to notify weather cron job running or not, you can set email id in cpanel 'cron jobs' page. so you will receive email once file get executed.
There are monitoring services specifically for cronjobs, doing exactly what you're asking for. I'm partial to WDT.io and here're the detailed instructions: https://cookbook.wdt.io/cron.html.

trigger a .sh script when a specific subject email is received

Anyway, I have a script that I want to run whenever I receive an email on gmail. And if possible a subject specific email. is such a thing possible and if so, what programs do I need to allow it.
You can't instruct gmail to trigger an external script for you. I think you've got a few basic choices. In order of increasing difficulty and complexity:
1) Configure a gmail filter to deliver your desired messages to a special folder. Write a script to poll that folder, download (or delete or mark as read) messages it finds there, and then launch your local script. Set up a cron on your local machine to run the script every few minutes. You can poll the folder with IMAP or the GMAIL API. IMAP is probably easier. This will be tricky with shell, you're better of with Python, PHP, or similar.
2) Configure a gmail filter to forward your desired messages to an address on a mail server that you control. Use procmail or similar to intercept the incoming messages and launch your script.
3) Set up an account at Mailgun and configure the emails so they get delivered there directly. (Or forward from gmail as in #2.) Configure Mailgun to launch an API request when it receives messages. Build an API handler to receive the request. Launch your process from your API handler.
I have never done it, but I guess the first thing you should do is to take a look at the Google's Gmail API...
What is the Gmail API?
The Gmail API gives you flexible, RESTful access to the user's inbox,
with a natural interface to Threads, Messages, Labels, Drafts, and
History.
It seems to fit what you want - at least, without knowing the details of what you want to do.
The Gmail API can be used in a variety of different applications,
including, typically:
Read-only mail extraction, indexing, and backup
Label management
(add/remove labels)
Automated or programmatic message sending
You can use several programming languages - maybe the trick is using your programming language of choice to write a wrapper for the .sh script... I hope this helps!

How to access some email, and print a specific mail's message body?

I have an email address email_reports#coldmail.com, on which some reports are received daily. How can I access that mail through a terminal, find a specific mail that I need (say, check the headers or the body for string DEBUG: Daily Data Report), and print out it's body to a file in a single piped command? I have Ubuntu 12.04 LTS, and the standard mail command, as well as mutt. I've tried searching for such functionality online, but all I've managed to find is guides on how to set up various mail agents, but not to process emails in a script-like fashion.
See http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/ for an excellent article on how to pipe incoming mail to a script. This technique can be used to pipe incoming mail to just about any kind of script, be it php, perl, python, etc.

Accepting image files via email from any address.

I am trying to build a service where anybody can send an image file from an email address/client and process it. Think about the service a bit like Flickr showing the image in a dashboard that comes via emails
From a usability standpoint this mechanic offers great deal of advantage but I want to understand the security consequences of such an action.Some concerns are:
I need to validate all these files as images
People can probably send a file with an exploit/code that can likely
be a problem. But in my case I am mostly going to do a file open and
save and let the browser show the image
Am I taking the right approach here? Are there serious consequences that I should be of?
Things you should do and take into consideration.
Make sure your mail server is configured for virus scanning, keep it up to date. That'll be the first line of defense.
When the email comes in, attempt to process the image in a known rock solid library.
Be aware that many emails contain multiple images, some of which may have nothing at all to do with the one they are sending. For example, our company emails all include our logo at the bottom. I'm not exactly sure what the solution is here, but you'll want to take it into consideration.
Different email clients handle image attachments, well, differently. Sometimes it's as a normal attachment, sometimes it's embedded in the body. Even within the same client an image might be handled differently depending on if they sent the email as plaint text with attachments or HTML mail.
People will test your system. They'll send .js files, they'll send images whose headers are jacked in order to overflow your image processing library...
Consider enforcing certain email restrictions such as SPF checks.
Be prepared to receive images that are absolutely huge. Today's cameras take very large photos and a lot of people don't know what crop or resize means. You might consider setting a cap of 15MB or larger per email coming into your server. Then, in combination with #2 above, auto resizing images down to something a bit more acceptable.
Determine the mechanism you actually want to use to notify the user of any issues. Bear in mind that this mechanism is subject to abuse. For example, consider a spam message sent to your machine with reply-to headers going to a victim.
If you are using .net, see this for a possible way to confirm a file is an image: How can I determine if a file is an image file in .NET?
I'm not saying this is 100% secure (can you ever be 100% secure?) but here is something that you can try:
Lets say that you have an alias on your postfix (or whatever mail system) that redirects incoming emails to a php/bash/python script for further processing.
The first thing I would do is use an image manipulation library (say imagemagick) and convert all incoming files to a .png format or whatever, and only proceed further with your logic if the conversion is successful.
This way, if someone sends you any malicious attachments (php exploit, jar's, swf's, anything) the conversion will fail, and hence it will be disregarded by your system.
Edit: ImageMagick has the "identify" command which does exactly what you want.
Emails could be easily spoofed as well, which means I can send an email from an email address which doesn't belong to me.
This might help also: Secure way to upload image in PHP ...

Resources