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!
Related
How do i send an email whenever a user requests it?. I thought on a script that sends mails every hour with some content relevant for the recipients, but I dont like the idea of spamming mail to other people. So i would like to send this mail whenever the recipients wants it. For example if this user sends me a mail with a keyword, i would like the sript to run and send the mail back with the content already made up. So, there is no spam and information is sent in a more efficient way.
I appreciate your help in advance.
This is a pretty complex and broad question.
First off, you would need a server or your PC to have the script running all the time or periodically fire off via cron.
Secondly, you would need to keep some kind of job queue where you would register that a user has sent you an email requesting that you send them one in response. There are well developed and complex job queues like Celery, but you could potentially do with something less complex - maybe a Google Sheets table.
Thirdly, you would need to parse emails you receive in order to get the keywords and email addresses. If you go the gmail + google sheets route, you could do it with some custom code probably, but otherwise you would need to implement email checking on your PC or server. Once you parse them, you add them to the jobs queue.
Finally, you need to provide email access to your Py script - meaning SMTP login. The docs have more on this.
As you can see, there are a lot of things to consider and implement, so you maybe better off trying to narrow down your question a bit. :)
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)
I have a working python program that sets IP/gateway/broadcast addresses for different devices using pySerial.
The basic idea would be that the user enters the addresses themselves and the program does the rest
IP = 'x.x.x.x'
broadcast = 'x.x.x.x'
gateway = 'x.x.x.x'
My initial thought was just to have the user open up the python program and change the addresses to whatever they want and then run it, but I came into a few problems
That's probably not the best practice to let the user do that
The user needs python installed
If I create an executable from my current code, the user won't be able to change the addresses to what they want
What would be the best way to allow users to enter their own addresses? The point of this script was to automate a proccess so getting user input didn't really make sense for me to do
There are several possible ways to do this, although the user will still need Python in some form to run your application. Having said that, if you package your application with a tool such as py2exe, it will package a minimal Python interpreter so that the user does not have to install it separately.
Use a configuration file that the script reads the addresses from.
Pass the addresses as arguments on the command line.
Ask a network service for the addresses.
I have many cron jobs running on various servers, I want to check the status of the jobs via mail using command line. The only way seems to me is to extract the subject or body of the mail the jobs sent. cron will send mail regardless of the success or failure.
For example, upon success cron will send a mail with subject:
Done..succeeded
If failed:
Not done..Failed
The cron jobs run at specific times e.g. lets take 10:00, 16:00 and 22:30 everyday.
I have tried curl and urllib2 but could not get desired result. Also note that i can not make any modification to cron itself, the only option is to check the gmail.
So how can i check my gmail from bash or python to extarct the subject so that i get get an idea of the cron job?
You can use imaplib to talk to Gmail with the IMAP protocol. This is the same protocol that you would use to have Gmail work with e.g. Thunderbird, so it’s fairly easy to retrieve messages rather than dealing with scraping often-changing HTML.
I had some python code that used to check gmail for me. I was going to post it but I tried it out and it no longer works for me. I haven't used it for about a year and Gmail has updated their auth to use oauth2 which is more secure. You may be able to get imaplib to work as well but you will need to enable less secure apps on your gmail account. If I have time to tweak it and get it working I will post it. In the meantime this link looks like a pretty good walk-through of how to get it working.
https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough
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.