lmachado Posted August 25, 2014 Share Posted August 25, 2014 (edited) First time trying to set up my own workflow...I found someone's blog post about using Alfred to send quick email messages: http://deskew.com/blog/?p=179 I followed all the instructions, but I'm getting the following error message when I test it: [ERROR: alfred.workflow.action.script] Code 126: /bin/bash: /Users/lmachado1/Dropbox/Alfred/extensions/scripts/quickmessage.py: Permission denied How do I fix this error? For your reference, the python script code is below. Thanks in advance! #!/usr/bin/env python3 #Edit these for your own server smptServer = 'something.something.com' sender = 'Something@something.com' username = "Something@something.com" password = "somepassword" import sys import argparse from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL) #from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption) from email.mime.text import MIMEText parser = argparse.ArgumentParser(usage = "echo <content> | quickmessage -s <subject> -r <recipient>" ) parser.add_argument("-r", "--recipient", required = True, help = "Email address of person to whom you want to send the message") parser.add_argument("-s", "--subject", required = True, help = "Subject line of the message") parser.add_argument("-m", "--message", required = True, help = "The contents of the message you want to send") args = parser.parse_args() subject = args.subject recipient = args.recipient #Read the body of the message from stdin #body = "" #f = sys.stdin #for line in f: # body = body + "\n" + line body = args.message try: theMessage = MIMEText(body, "plain") theMessage['Subject'] = subject theMessage['From'] = sender # some SMTP servers will do this automatically, not all theConnection = SMTP(smptServer) theConnection.set_debuglevel(False) theConnection.login(username, password) try: theConnection.sendmail(sender, recipient, theMessage.as_string()) print ("Mail sent: " + body) #Show this in notification center if you want finally: theConnection.close() except Exception as e: print ( "Unable to send email message: " + str(e) ) sys.exit( "Unable to send email message: " + str(e) ) Edited August 25, 2014 by lmachado Link to comment
dfay Posted August 25, 2014 Share Posted August 25, 2014 Funny I was thinking of writing something like this myself a few days ago, but decided against it b/c I didn't think Alfred was the right vehicle given the need to enter recipients, subject and message. But - if you want to try to use this script - those directions leave out a critical step. After you copy the quickmessage.py file in place, you need to change the file permissions to make it executable. In Terminal cd into that directory then use the command chmod 755 quickmessage.py (brief discussion of permissions here: https://www.linode.com/docs/tools-reference/modify-file-permissions-with-chmod ). A couple other issues I see with this approach are that 1) (trivially) line 4 should be smtpServer not smptServer and 2) (more seriously) this script requires you to hard-code your e-mail password in plain text. Also 3) as written the script requires you to install python 3 which isn't installed on Mavericks by default. Link to comment
lmachado Posted August 25, 2014 Author Share Posted August 25, 2014 Thanks so much for your reply dfay! I completely agree that Alfred is not a great vehicle for email messages...I'm creating this workflow for quickly emailing short notes to myself, similar to this iOS app I use: https://itunes.apple.com/us/app/captio-email-yourself-1-tap/id370899391?mt=8 - ie. "note remember to pick up milk" would send an email to myself with "remember to pick up milk" in both the subject and message body. I believe I know how to modify the workflow to make that work... I also don't like that the script requires me to hard-code my email password in plain text...But since I'm just using this to send notes to myself, that's ok...I'll just create an email specifically for this, so the security isn't a concern... Thanks again for your help! I'll make these changes now and report back with the results Link to comment
lmachado Posted August 26, 2014 Author Share Posted August 26, 2014 Dfay - Once I followed your instructions and set the proper python directory on line 1 it worked! Thanks! Link to comment
dhjdhj Posted August 26, 2014 Share Posted August 26, 2014 I'm the one who wrote the script at deskew.com and just noticed this discussion thanks to someone emailing me yesterday. So a couple of observations. First of all, thanks for noticing the permissions issue. I forgot to mention that and have updated my blog entry accordingly. Easy to forget that such things are not obvious to users who don't do command line stuff a lot. You're also correct that it requires Python 3 and I've added into to the blog as to where to get it. Like Apple, I like to use the latest and greatest rather than legacy stuff :-) While smptServer rather than smtpServer (Simple Mail Transfer Protocol, for anyone who cares) is certainly a typo, it's a variable name and the same variable name is used everywhere, therefore the typo has ZERO semantic impact on the behavior of the program, so it isn't an "issue", no matter how trivial. Wanted to clear that up just in case someone thinks it is in fact an issue. You're correct that password is plain text. But it's in a file you control on your own machine. The password that goes out to the server is encrypted and that's really all that matters. However, most importantly, I find that the ability to send quick emails to a few of my friends (and my wife) by simply typing their name and a message directly into Alfred to be extremely productive. I can be in the middle of working on any project (development, writing, music, whatever) and it is not neccessary to switch away from that activity to open your mail program and fill in all the fields just to send a quick message. I think that once you try it, it becomes a key utility that does not interrupt your workflow. Clearly lots of ways to make this better -- I tried to figure out how to grab the email address directly from contacts so that I wouldn't be restricted to just a few people. I forget now why I wasn't able to do it but it's low priority at this point. Link to comment
lmachado Posted August 26, 2014 Author Share Posted August 26, 2014 Thanks for the blog post dhjdhj! I've already used it a ton to email myself quick notes! If you ever make improvements, it would be great if you could post it on the Alfred Forum...Thanks again! Link to comment
dfay Posted August 26, 2014 Share Posted August 26, 2014 thanks for following up djhdjh Link to comment
johnnyd Posted October 13, 2014 Share Posted October 13, 2014 Hi, I'd really love to get this working but am stuck. I'd be v grateful for a bit of help. If I run >python quickmessage.py -r blahblah@me.com -s "Quick message from me" -m "hello" to test if I have the quickmessage script set up ok, I get an error. Unable to send email message: SMTP AUTH extension not supported by server. If I switch to SMTP_SSL in the script I get Unable to send email message: [Errno 60] Operation timed out Is this because I am trying to use iCloud as my SMTP server (smptServer = 'smtp.mail.me.com'), and Apple does not permit this usage? And if so, is there some sort of alternative set up that will allow me to send a message that comes from (or appears to come from) my blahblah@me.com email address? Thanks very much for any help, and thanks for sharing this workflow! Link to comment
dhjdhj Posted October 13, 2014 Share Posted October 13, 2014 Unfortunately, there are various different options depending on what server you're trying to connect to, what ports are opened by your ISP and so forth. Here's the link for the SMTP class https://docs.python.org/2/library/smtplib.html and here are the settings that icloud seems to want http://support.apple.com/kb/ht4864 Link to comment
johnnyd Posted October 13, 2014 Share Posted October 13, 2014 Great - so I've fixed my username now, that should be the full address @me.com according to that apple doc. But how do I set the required port of 587? I tried changing line 15 to: from smtplib import SMTP_SSL(,587,,,,) as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL) but this just gives a syntax error: File "quickmessage.py", line 15 from smtplib import SMTP_SSL(,587,,,,) as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL) ^ SyntaxError: invalid syntax Probably making some basic Python error (total newbie on this) - if there is an obvious quick fix then please could you let me know? Is the local_hostname required - what should go here? Thanks so much for the instant response! Link to comment
dhjdhj Posted October 14, 2014 Share Posted October 14, 2014 I'm regret I'm not in a position to teach Python right now (sorry) but you certainly don't change the port in an import statement so dump those parentheses and make that line back to from smtplib import SMTP_SSL as SMTP (Note, that I have not tested this with SSL support) The port is set when you create the connection, which is on line 46 of my code theConnection = SMTP(smtpServer,26) However, if you have to use SSL, then you might have to deal with certificates (typically you will just want to ignore them). There's an example on stackexchange that might help you http://stackoverflow.com/questions/64505/sending-mail-from-python-using-smtp However, be aware that python3 (which I used) has slightly different syntax from the older python2 Sorry I can't help you completely troubleshoot this. Link to comment
lmachado Posted September 17, 2015 Author Share Posted September 17, 2015 So I had been using this just fine for quite a while now, and yesterday I got a new Macbook Pro so I installed python, copied the script over, confirmed permissions were properly set, etc...But it's not working for me on the new machine...Alfred isn't spitting any errors. Also, I get the notification saying that the mail was sent. However, I never receive an email... I went into webmail for the sending account, figuring that I'd check there to see if the messages were in the sent mail folder, but the sent mail folder is completely empty. This tell me nothing, since I guess none of the notes were ever showing up in the sent folder. Any ideas what might be going wrong here? Thanks! Link to comment
deanishe Posted September 17, 2015 Share Posted September 17, 2015 You aren't really providing enough information to work with. Try running the script in your shell, and if your code isn't exactly as in your first post, post the source code (excluding your login details, naturally). Which version of Python are you using? Where is it installed (e.g. /usr/local/bin/python3)? Link to comment
lmachado Posted September 17, 2015 Author Share Posted September 17, 2015 Yeah, I figured this wasn't enough info, but I wasn't sure what else to provide...Figured an expert could help guide me Yes, python is found in /usr/local/bin/python3: "$ sudo find / -name python3" in terminal results in: find: /dev/fd/3: Not a directory find: /dev/fd/4: Not a directory /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 /usr/local/bin/python3 I installed Python 3.5 from python.org Thanks! Link to comment
deanishe Posted September 17, 2015 Share Posted September 17, 2015 Don't use "find" to find programs: it takes too long. Use "whereis" or "which". Can you run "ls -l /usr/local/bin/python3" to see if that python3 is a symlink to the other one? Also run "which python3" to see which one your system preferentially uses. Then in your shell, run "python3 /path/to/your/script.py" and see what happens. Link to comment
lmachado Posted September 17, 2015 Author Share Posted September 17, 2015 $ ls -l /usr/local/bin/python3 lrwxr-xr-x 1 root wheel 69 Sep 17 11:19 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.5/bin/python3 $ which python3 /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 when i run the script in the terminal, it looks like it runs successfully...gives me the "Mail sent: <message>" response: $ /Library/Scripts/quickmessage.py -r emailaddy@email.com -s testing1235subaaaaaj -m testing1235msgasdfsdf Mail sent: testing1235msgasdfsdf Link to comment
deanishe Posted September 17, 2015 Share Posted September 17, 2015 Okay, so they're the same Python. Was the email actually sent successfully? Did it end up in your spam folder or was otherwise filtered? Link to comment
lmachado Posted September 17, 2015 Author Share Posted September 17, 2015 Geez, I feel like an idiot...they are all in spam...I didn't even think of checking because I've been using this workflow for over a year and never had this problem. I just looked, and only the notes I started sending today are in there - none before that. And I tried sending some notes just now from the computers I've been using this workflow on and they also went to spam. So odd that this randomly started happening just as I set up this workflow on a new machine... Sorry for the trouble and thanks for your help! Link to comment
deanishe Posted September 17, 2015 Share Posted September 17, 2015 (edited) We all have our dumb-ish moments, and as you say, the mails hadn't landed in spam before. Glad it's working for you. Edited September 17, 2015 by deanishe Link to comment
lmachado Posted October 8, 2015 Author Share Posted October 8, 2015 So this morning this workflow/script stopped working...In the time it took me to write this post (about an hour as I had to deal with some work stuff in between) it suddenly started working again...So I figured I'd make the post anyway as I'm curious what may have caused this... So, when running the workflow I was getting this error: [ERROR: alfred.workflow.action.script] Unable to send email message: [Errno 60] Operation timed out I tried running the script in terminal and I just get the same exact error: Unable to send email message: [Errno 60] Operation timed out My next thought was to login to the email I use to send these messages to make sure the username/password was still correct (I didn't change it, so it should be, but you know...testing...) - it's still the same. So then my last thought was to login to my web host and make sure the mail server settings didn't get changed by my web host - nope, they are still the same... So, it looks like nothing changed...It just suddenly stopped working, then an hour or so later it was working again...Any ideas why this happened? Thanks! Link to comment
deanishe Posted October 8, 2015 Share Posted October 8, 2015 Error number 60 is a socket timeout error (it couldn't connect to your server). Either there was a temporary network problem between you and your mail server or your mail server was briefly offline. Link to comment
lmachado Posted October 8, 2015 Author Share Posted October 8, 2015 Error number 60 is a socket timeout error (it couldn't connect to your server). Either there was a temporary network problem between you and your mail server or your mail server was briefly offline. Ah, ok! Got it! Thanks! Link to comment
Geir Posted June 8, 2016 Share Posted June 8, 2016 Hi! I have a short cut: ctr + Z that let me send an email to myself quickly. I found the solution in Forum or so. I worked a long time, but now it won't. I get: Send email to Geir Fossnes, but when I tap enter it goes to the wem site and search for "email Geir Fossnes" in Google. What have I done to destroy this nice shortcut? Sombody to help me? Link to comment
deanishe Posted June 9, 2016 Share Posted June 9, 2016 Dude, we're not psychics. How are we supposed to tell you what's wrong with a workflow we've never seen? Link to comment
Geir Posted July 10, 2016 Share Posted July 10, 2016 Hi again! YES I am sure that I could do this before in Alfred. I used it massive. The point is to send an email to myself I'm Mac Mail easily: 1. Tap a shortcut (ctr+z) 2. Write the message in the email 3. Send The solution is like "Captio" for iPhone....Have a look on this tiny program in App store....(but it do not work on Mac) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now