Python Forum
send email after restart raspberry pi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
send email after restart raspberry pi
#4
I prefer the emails package. To use it, you have to install it on your Raspberry Pi.
Also you have to check the settings. Some providers do have different ports.

You can install the package as root:
pip3 install emails
or as unprivileged user:
pip3 install emails --user
or you can use a virtual environment as normal unprivileged user:
python3 -m venv python_env
source python_env/bin/activate
pip install emails
Later you have to use the symlinked binary python in the virtual environment.
YourHomePath/python_env/bin/python YourScript.py
Then you can try this code, after you have filled in all credentials, host, port, etc.
Try this, if this works.
Then the next step is to check, if @reboot works with cron.

import emails
import datetime

now_str = datetime.datetime.now().isoformat()

# you can also use only text
html_message = '''
    <h1>Restart at:</h1>
    <p>{}</p>
    '''.format(now_str)
text_message = 'Restart at:\n' + now_str 
subject = 'Restart'
mail_from = ('My Raspberry Pi', '[email protected]')
to = ['[email protected]']
smtp = {
    'host': 'securesmtp.t-online.de',
    'port': 587,
    'tls': True,
    'timeout': 5,
    'user': '[email protected]',
    'password': 'MySuperSecretPassword',
    }

message = emails.html(
    html=html_message, text=text_message,
    subject=subject, mail_from=mail_from
    )

result = message.send(to=to, smtp=smtp)
print(result.status_code, result.status_text)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
send email after restart raspberry pi - by chano - Jun-05-2019, 09:48 AM
RE: send email after restart raspberry pi - by DeaD_EyE - Jun-06-2019, 01:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Virtualenv with auto restart JohnnyCoffee 3 2,887 Apr-27-2021, 05:27 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020