I’m not sure if there is a better way of describing my issue, but here goes:
I have written a program on my personal computer (python) that I can run, but I want to run it when triggered by receiving an email automatically.
In other words, when I receive an email with a certain header/text, run this specific program.
What is a secure way of sending this signal to my computer such that it will queue to run when I am logged in? My computer is a laptop and is frequently asleep and I don’t want to lose the signal to run the program.
Thank you in advance!
After a few months, I've come up with an answer - configuring your email with IMAP. I was able to do this with gmail.
There is a built-in IMAP library for python called imaplib that allows you to do the trick.
Basically you can query the inbox and search for a file every X minutes, and run a command if a specific type of email is found.
(Idea from mrooney/minapi)
Related
I've been writing some python scripts in order to do some automation for my work. One of the scripts is intended to gather some test results, compile the string of results with a "message" string, and send it as an email every 12-24 hours (if there are results) to each individual who needs this information. Additionally, we're running this script on Linux; either in a Jenkins pipeline, or in a crontab (this script will most likely be run via crontab).
I was initially using gmail's SMTP server (smtp.gmail.com, port 587) to send these since we're working off of our own personal gmail server anyways, and it worked for a bit once I gave the script an "App Password" since it was a "less secure app" to Google. However, after about an hour of testing with it, Google disabled the account for spam. Any subsequent accounts I try to set up for the same purpose are disabled on the spot, as well (the moment I try to send an email with it, it's halted and disabled). It's been a few days since I requested reviews on both of the accounts; but I don't think they'll get back to me any time soon, nor will it be a result in my favor.
Since Google was no longer viable, I looked online and saw that there are plenty of SMTP hosting options available, but we're not looking for a paid service just to send an email once every few days or so. In terms of free options, I was able to find one other post related to PHP/Ruby sending emails without SMTP (Send email without external SMTP service), but if possible I'd like to keep this within Linux/Python only unless there is a simpler way, or a way that links well with Linux/Python. Even then, I'm still concerned that using SMTP is necessary for our gmail accounts to receive these emails. If I'm wrong, please correct me; because it certainly seems that way to me.
Based off of the situation, how could I adjust my strategy in order to automate email updates of this nature?
I have got the Wake On Lan feature working. But after I start the computers they get stuck at the windows login screen obviously as the computers have passwords.
Is there any way to auto login after Wake On Lan or somehow automate the login process without removing the password. I found threads discussing a possibility that you could run a script as a service or something, but couldn't find a working solution.
I found a way to do this with Python and Windows Task Scheduler. With Task scheduler you can run tasks based on events like startup. I created a Python script that changes the password to a blank one and restarts the computer, this way it doesn't require the password for login. In Task Scheduler you have to check the run with highest privileges and run whether the user is logged in or not. Then I created another script that after log in event changes the password back to what it was.
In my opinion this is some kind of security flaw but more experienced people can give their opinion about that.
I have a Python script that should control if an incoming email in Outlook is the one expected, with the expected attachment.
For example:
I'm waiting for an email from duffy#duck.com. when I receive an email, I check whether the sender is duffy#duck.com or not. If it is, I go on and check the attachment; otherwise I stop the read and wait the next email.
What I would like to have is not a continously running script, but an automatically launched script when the event "Outlook received an email" is catched.
I have no idea, how I could manage this situation. I hope everything is clear.
In the following example, you can see how to trigger an application via email in Outlook, using 'Rules and Alerts' option.
BTW, there's another example for that.
As Gal Dreiman suggested, the solution is:
Create Rules in Outlook with a Python Script. Launch it and rules will be permanent in Outlook, until the user delete. In this way the sender check is automatically and an other Python script might be launched.
Furthermore I share a link in which an example, about how to implement a rule in Outlook with Python, is shown.
EDIT
As written here, it's not possible to create programmatically rules, to call and run scripts.
I can't find any workaround!
I just learned how to read and send emails using python and I read that you can create a python script that can read someone's twitter or facebook and send you an email whenever a specific person posts something on twitter or facebook, but how does this work?
What is the difference between a script and just a regular program? I don't think that if someone is doing something like this that they would need to have their computer on at all times and have the python program running in the background, or is that what is happening?
A python script is a kind of program.
To make what you're talking about, you'd need to either have some kind of notification when someone tweets or something to check constantly for new content.
Either way, the computer will have to be on at all times (for that, you could use a Raspberry Pi for example, so you don't take that much power). (EDIT : you can of course also have a server doing that for you, but it's still a computer running at all times.)
You'll need to get your hand onto the Twitter API documentation. There is probably a python wrapper.
(EDIT:Tweepy - Would be the aforementioned python wrapper)
I am working on a project for work that requires me to pull information from a logfile and send a notification anytime it finds a the specific information. For example the exact issue I am working on is I am needing to create a python script that will look into may /var/log/auth.log (FreeBSD system) and pull any invalid SSH login attempts, then proceed to email me and another co-worker anytime there is an offense.
I've been looking all over for a few days now and have had minimal success any help would be greatly appreciated.
I think what you're really after is a daemon like fail2ban, which is specifically designed to examine log files for intrusion attempts.
From the fail2ban wiki:
Fail2ban scans log files (e.g. /var/log/apache/error_log) and bans IPs
that show the malicious signs -- too many password failures, seeking
for exploits, etc. Generally Fail2Ban then used to update firewall
rules to reject the IP addresses for a specified amount of time,
although any arbitrary other action (e.g. sending an email, or
ejecting CD-ROM tray) could also be configured. Out of the box
Fail2Ban comes with filters for various services (apache, curier, ssh,
etc).
This would probably work better than any solution you baked yourself.
That said, if you did want to roll your own, the naive way to implement periodic checking of a file is simply to read it every five minutes and see if it's changed.
The smarter way is to use the operating system's file monitoring service, which hooks into the filesystem driver and notifies you as soon as the file changes. This has the dual benefits that your code will take less CPU time, and it will respond immediately whenever the file changes.
On Linux the service is called inotify. BSD and Windows have an equivalent feature.
You could run a cron job every few minutes that checks for changes in that file. If there are any changes, it will email you, by using, for example, smtplib. Here is an example of smtplib usage with sendgrid: http://docs.sendgrid.com/documentation/get-started/integrate/examples/python-email-example-using-smtp/
How do you find out if a file was modified?
You keep a copy of the file as it looked in the previous script run, and compare that to the current contents
You check the file's last modification time.
This is just a general idea that can be tweaked, and all the 'ingredients' can be found on google, so you should be able to implement it by googling yourself.
Hope this helps.
As a rough idea for a cron job:
with open('/var/log/auth.log') as auth:
for line in auth:
if 'blahblah' in line:
# send email
You'll want to check out the email module for emailing details. You'll also want a way to keep track of what's already been scanned, so you don't end up sending duplicate emails.