You are not logged in.

#1 2011-05-07 19:44:57

y27
Member
Registered: 2009-05-27
Posts: 147
Website

jsm.py -- Just Send Mail -- simple email sending script

Recently I built myself a small toy server, and I figured I could use it for monitoring purposes and stuff, checking what's up with my larger server. Thus I wanted a way for the small server to notify me in case something went wrong.

The natural way for this was email, but as far as I knew, all solutions were relatively complex, overkill and annoying to set up.

So I just created jsm.py, a (really) small Python script that simply takes the From, To, Subject, Message arguments and sends out an email by itself, no need for an SMTP server (it finds the appropriate SMTP server automatically with MX DNS records).

Hopefully it might be useful to more people than just me smile

Source : https://github.com/houbysoft/short/blob/master/jsm.py
AUR : http://aur.archlinux.org/packages.php?ID=48823


As always, comments and suggestions welcome, I wrote this in about 5 minutes so I'm sure there's room for improvement.

Offline

#2 2011-07-06 17:33:19

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: jsm.py -- Just Send Mail -- simple email sending script

y27 wrote:

Recently I built myself a small toy server, and I figured I could use it for monitoring purposes and stuff, checking what's up with my larger server. Thus I wanted a way for the small server to notify me in case something went wrong.

The natural way for this was email, but as far as I knew, all solutions were relatively complex, overkill and annoying to set up.

So I just created jsm.py, a (really) small Python script that simply takes the From, To, Subject, Message arguments and sends out an email by itself, no need for an SMTP server (it finds the appropriate SMTP server automatically with MX DNS records).

Hopefully it might be useful to more people than just me smile

Source : https://github.com/houbysoft/short/blob/master/jsm.py
AUR : http://aur.archlinux.org/packages.php?ID=48823


As always, comments and suggestions welcome, I wrote this in about 5 minutes so I'm sure there's room for improvement.

How does it work? I installed it but do not see a man page / --help. Could you give me an example. What I am trying to do is send a lot of emails one after the other. I was hoping to do a for each loop or similar.

Offline

#3 2011-07-06 22:13:10

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: jsm.py -- Just Send Mail -- simple email sending script

It tells you the usage if you run it without arguments, or incorrect ones (so you could pass --help if you want, it would show it).

[j@universe ~]$ jsm
Usage : /usr/bin/jsm FROM TO SUBJECT MESSAGE
 FROM is the email address to send from
 TO is the email address to send to
 SUBJECT is the email's subject
 MESSAGE is the message to send

This program is (c) Jan Dlabal, 2011, and is available under the terms of the GNU GPL v3 License.

So an example, if I wanted to send an email with subject "This is a test", message "Hi, how are you?" from myemail@mydomain.com to you@yourdomain.com, I'd run:

jsm myemail@mydomain.com you@yourdomain.com "This is a test" "Hi, how are you?"

Don't forget the quotes of course.

Offline

#4 2011-07-06 22:33:56

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: jsm.py -- Just Send Mail -- simple email sending script

y27 wrote:

It tells you the usage if you run it without arguments, or incorrect ones (so you could pass --help if you want, it would show it).

[j@universe ~]$ jsm
Usage : /usr/bin/jsm FROM TO SUBJECT MESSAGE
 FROM is the email address to send from
 TO is the email address to send to
 SUBJECT is the email's subject
 MESSAGE is the message to send

This program is (c) Jan Dlabal, 2011, and is available under the terms of the GNU GPL v3 License.

So an example, if I wanted to send an email with subject "This is a test", message "Hi, how are you?" from myemail@mydomain.com to you@yourdomain.com, I'd run:

jsm myemail@mydomain.com you@yourdomain.com "This is a test" "Hi, how are you?"

Don't forget the quotes of course.


Wow. This thing just works. Cool. Thanks man. I sent from gmail to gmail. The only problem I have now is that gmail is saying it is not authentic. Which makes sense because it's not. Is there any way to put in my credentials so that it goes through from my gmail?

Offline

#5 2011-07-07 00:34:43

freak
Member
Registered: 2009-04-15
Posts: 17

Re: jsm.py -- Just Send Mail -- simple email sending script

dodo3773 wrote:

Is there any way to put in my credentials so that it goes through from my gmail?

This would definitely be nice.  It would also be useful if it could read the body through stdin, instead of as an argument.

Offline

#6 2011-07-07 03:12:21

tacticalbread
Member
From: Bay Area, CA
Registered: 2011-04-09
Posts: 127
Website

Re: jsm.py -- Just Send Mail -- simple email sending script

Wonderful, this should be quite useful for me. Thanks for sharing!


don't save us from the flames

Offline

#7 2011-07-07 03:15:04

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: jsm.py -- Just Send Mail -- simple email sending script

freak wrote:
dodo3773 wrote:

Is there any way to put in my credentials so that it goes through from my gmail?

This would definitely be nice.  It would also be useful if it could read the body through stdin, instead of as an argument.

Can't believe I didn't implement that. I updated the package in AUR, now it accepts the message through stdin if it is not specified as an argument. For the logging into gmail, that could probably easily be added, but right now I don't have too much time. If you know Python, you're welcome to send me a patch, the entire program is literally 42 lines so it should be straightforward to understand.

Offline

#8 2011-07-07 03:31:34

y27
Member
Registered: 2009-05-27
Posts: 147
Website

Re: jsm.py -- Just Send Mail -- simple email sending script

Oh and dodo3773, I had a similar issue with gmail, it was classifying messages as spam.

If you are using it like me, i.e. just to send messages to yourself, you can easily fix that problem by making up an email (like a95tngbi4@yourdomain.com), and always using it as the FROM argument with jsm. Then, in Gmail, setup a filter to always mark messages from a95tngbi4@yourdomain.com as important, and never send to spam. Works great for me smile

Offline

#9 2011-07-07 04:27:11

dodo3773
Member
Registered: 2011-03-17
Posts: 818

Re: jsm.py -- Just Send Mail -- simple email sending script

y27 wrote:

Oh and dodo3773, I had a similar issue with gmail, it was classifying messages as spam.

If you are using it like me, i.e. just to send messages to yourself, you can easily fix that problem by making up an email (like a95tngbi4@yourdomain.com), and always using it as the FROM argument with jsm. Then, in Gmail, setup a filter to always mark messages from a95tngbi4@yourdomain.com as important, and never send to spam. Works great for me smile

Just tried it. I made up a domain for the FROM part and it still got flagged. Also, I wish that I could help more with coding but I do not know any python.

Edit: Please ignore. I did not read the "always mark messages from a95tngbi4@yourdomain.com as important, and never send to spam" part. My fault. Wish there was a better way though.

Last edited by dodo3773 (2011-07-07 21:09:10)

Offline

Board footer

Powered by FluxBB