For X or Y reasons, sometimes we need to program the server of our company to do a certain task, and we want to know if this task was executed without problems, for this we program that if everything went smoothly, notify us… but… ¿ How can the server notify us?
Very simple, we will tell you through a script Python to send us an email, in this way when we check the mailbox, we will read if the server had no problems to place the order.
The script left them here: send-email.py
To use it is very simple, open a terminal, in it write the following and press [enter]:
cd $HOME/ && wget http://paste.desdelinux.net/paste/?dl=89 && mv index.html\?dl\=89 send-email.py && chmod +s send-email.py
I leave you how the process would be:
% CODE1%
Once this is done, you must edit the script to put your own data, I will edit it by putting my data, that is, the data from here my work.
Open the script (send-email.py) and change this data:
- your email@desdelinux.net by your email (in this example - » kzkggaara@ipichcb.rimed.cu)
- Message body by the content of the email (in this example - » This is a test email)
- you.mailserver.cu by your mail server (in this example - » 192.168.1.2)
- your email by your user (in this example - » kzkggaara)
- your-password for your password (in this example - » HAHA… yeah… sure… LOL)
It looks like the following: send-email.py (Modified)
And voila, it only remains to send the email ... for this we will put the following:
- python send-email.py "Here we put the subject" recipient@domain.com
In other words, we must execute the script and pass it the "Subject" parameter (that is, the subject that the email will take) and also to whom (email address) it will be sent.
I will send myself an email, here is the example:
% CODE2%
And now 😀
As you can see, something quite simple ... but it can help us on certain occasions 😉
regards
it's very good .. but i want something like this that works for windows but i can't find it 🙁
For Windows ... mmm ... you must install Python on Windows friend: http://www.python.org/getit/windows/
for windows there is a tool called Cobian, it is very good and intuitive
how to enable the script to send with gmail (smtp)?
I have the same question: /
I could:
s = SMTP ('smtp.gmail.com')
s.starttls () # If you use TLS
s.ehlo ()
However it gives me this error:
python send-email.py "Here we put the subject" aquimi@correo.com
Traceback (most recent call last):
File "send-email.py", line 14, in
s = SMTP ('smtp.gmail.com')
File "/usr/lib/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect (host, port)
File "/usr/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket (host, port, self.timeout)
File "/usr/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection ((port, host), timeout)
File "/usr/lib/python2.6/socket.py", line 561, in create_connection
raise error, msg
socket.error: [Errno 101] The network is unreachable
It's good, and then you program it with cron and ready to report: D.
Yes! hehe, save a lot of time automate things with scipts 🙂
Thanks for the post, I find it interesting and adding the functionality that Reedyseth cites has one more utility. 😉 greetings compas!
Thanks to you for the comment 😀
Greetings friend.
Gaara, my friend, I'm sure this article is very good as everyone here highlights but I - NO-PUE-DO-SE-LOS-E-JEM-PLOS-POR-MI-MAL-DI-TA-CO-NEC- TION
WHAT DO I DO TO SEE THEM, CUT MY THROAT?
Can't open this link? - » http://paste.desdelinux.net/89
Let me ask you something, could I make a script so that on a certain day I can send a specific message to all the users of my center? I guess so, but you are the specialist and if you confirm this, could you help me make one?
Yes, to do "something" on a given day you must use crontab.
Then, assuming you want to send a .PDF file (for example, note.pdf) to your users, to send to only 1 email would be:
mail -s "Este es el asunto del correo" direccionemail@loquesea.cu < nota.pdf
Now, to send that but not only to one address, but to many more ... you would need to have the addresses in a text file (separated by a line break), and then use a loop for. For example, if you have the emails in addresses.txt, it would be:
for i in `cat direcciones.txt`;
do
mail -s "Este es el asunto del correo" $i < nota.pdf
done
Thanks buddy, the script works great.
Where is the script if you can help me
Can you please share the examples ????