Send email from a Python script on the Raspberry Pi

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ม.ค. 2025

ความคิดเห็น • 94

  • @LaurieMcIver
    @LaurieMcIver 10 ปีที่แล้ว

    This was brilliant! Just got R-pi for Christmas and wanted to do coding. Found this video and thought I would try it. Had some trouble getting the files, but it was because of spelling errors. I had to debug a few times because of double key presses but it was worth seeing the email come into my email account! THANKS!

  • @martinaplante4035
    @martinaplante4035 10 ปีที่แล้ว

    I'm already using ssmtp with errors. This tutorial fix the problem! Now it works fine. Thank you! You make good tutorials, clealy explained.

  • @updowndown
    @updowndown  11 ปีที่แล้ว

    Good to hear the proper solution! I guess when in doubt, do an update/upgrade or just install the latest version of Raspbian.

  • @Daikon18
    @Daikon18 8 ปีที่แล้ว

    followed instructions to the T and had it working right out of the gate. Thanks Gaven! Liked and Subscribed!

  • @updowndown
    @updowndown  11 ปีที่แล้ว

    Good question. I'll make a short video in the next few days on how to extend this for sending a text to a phone.

  • @yTitoStyleRy
    @yTitoStyleRy 10 ปีที่แล้ว +17

    When I am using the terminal to send an e-mail I always get the notification:
    mail: cannot send message: Process exited with a non-zero status

    • @beetlewing
      @beetlewing 9 ปีที่แล้ว

      I'm getting this error as well, on a fresh, updated installation. Anyone have a fix?
      Also, if body of email ends with an exclamation point, like "Hello Email Test!" I get this error:
      bash: !": event not found

    • @anandkrishnan72
      @anandkrishnan72 8 ปีที่แล้ว

      Try and change your password to make bit simple without any larger symbols, this fixed it for me.

    • @gage3809
      @gage3809 6 ปีที่แล้ว +1

      For anyone with this issue: Google may have blocked your attempt. It sees this method as a security issue. Go into your google settings and lower your security for this to work.

    • @moritzeigenauer8830
      @moritzeigenauer8830 6 ปีที่แล้ว +1

      Ok. But what i have to do in the settings?

    • @meow-xs3vw
      @meow-xs3vw 6 ปีที่แล้ว

      This happened to me as well but i remedeed this by getting a new raspbery pi b3+

  • @PiotrSamek
    @PiotrSamek 3 ปีที่แล้ว

    Thank you! Works like a charm, and the shell command I use in Crontab ;)

  • @pesmaster10
    @pesmaster10 8 ปีที่แล้ว +1

    I LOVE YOU.. Trying was more than 6 hours without sleep how to do this. And thank you I did it

  • @henryh3643
    @henryh3643 6 ปีที่แล้ว

    Great Video, very simple but extremely effective and useful.

  • @mrinquisitive7240
    @mrinquisitive7240 11 ปีที่แล้ว +1

    Very helpful, thank you. Also, thanks to Terry Gold for pointing out that "import smtplib" needed to be added to the script - it didn't work until I added this.

  • @lowmunseong106
    @lowmunseong106 10 ปีที่แล้ว +1

    would it be possible to send an image file aswell if so how would i be able to do that. thanks

  • @TheStefano009
    @TheStefano009 8 ปีที่แล้ว

    Works perfectly! Thank you very much!

  • @franciscogutierrez1925
    @franciscogutierrez1925 10 ปีที่แล้ว

    Thanks Gaven you are a genius

  • @mitchh16
    @mitchh16 11 ปีที่แล้ว

    Great info! Any idea how you could get an sms or push notification from the pi?

  • @International_Criminal_Court
    @International_Criminal_Court 5 ปีที่แล้ว

    THANK YOU SO MUCH! Amazing tutorial! Perfectly works! Subscribed!

  • @cipmars
    @cipmars 6 ปีที่แล้ว

    Very useful, thank you. I will use this in a project with RFID access control.

  • @mckubzie
    @mckubzie 11 ปีที่แล้ว +3

    would you happen to know how to add an attachment, or a picture from a camera as an attachment to the email, very helpful video btw

  • @AmrishKelkar
    @AmrishKelkar 7 ปีที่แล้ว

    worked for me right off the bat. I created a ghost gmail account that I can use to send emails so that even if my rpi gets hacked, there's not much to lose, since there is no private information in that account anyway.

  • @updowndown
    @updowndown  11 ปีที่แล้ว

    Hmm .. I haven't encountered that issue. It sounds like something is blocking the connection, so you may want to check your firewall settings.
    If that doesn't work, Google "Cannot open smtp.gmail.com:587" and you'll find several sites discussing the issue. Hope that helps.

  • @adspooren
    @adspooren 6 ปีที่แล้ว

    Thanks very much! Works!

  • @updowndown
    @updowndown  11 ปีที่แล้ว

    I've heard of someone having that problem and it had to do with the password in the config file. That person changed their gmail password and it fixed the problem. Anyway, just google "SMTP Mail Server Help raspberry pi" without the quotation marks and the first link will take you to the discussion about the issue.

  • @ryanmiller9388
    @ryanmiller9388 10 ปีที่แล้ว

    Thank you, it worked perfect

  • @SuperHaunts
    @SuperHaunts 5 ปีที่แล้ว

    Just what I needed!

  • @txsatelectronics6156
    @txsatelectronics6156 6 ปีที่แล้ว

    Do you have any videos on how I can set up my temp module to send me an email once it gets to a certain temperature? Thanks!

  • @icarus7471
    @icarus7471 7 ปีที่แล้ว

    pretty good , nice job

  • @YacineHarboula
    @YacineHarboula 6 ปีที่แล้ว

    i have an issue any solution ? : Traceback (most recent call last):
    File "email.py", line 1, in
    import smtplib
    File "/usr/lib/python2.7/smtplib.py", line 46, in
    import email.utils
    File "/home/pi/email.py", line 8, in
    header = 'To: ' + toAdd + '
    ' + 'From: ' + FromAdd + '
    ' + Subject
    NameError: name 'FromAdd' is not defined

  • @VinceTheGodd
    @VinceTheGodd 10 ปีที่แล้ว

    This is pretty cool.

  • @TheKennyCollins
    @TheKennyCollins 10 ปีที่แล้ว +1

    Hi there,
    thanks for the tutorial, I have been able to send email using the echo method, but when I try to do it from your exact script, I get this;
    "Traceback (most recent call last):
    File "myemail.py", line 1, in
    import smtplib
    File "/usr/lib/python2.7/smtplib.py", line 46, in
    import email.utils
    File "/home/pi/email.py", line 19, in
    except SMTPException:
    NameError: name 'SMTPException' is not defined"
    I thought I had updated my system, what am I missing?
    Thanks in advance!
    Kenny.

  • @moisesv.5206
    @moisesv.5206 7 ปีที่แล้ว

    Do you think it'd be possible to wire up and program a zero w pi to be a laser trip wire that when activated could use this code to send an email alert?

  • @TerryGold1
    @TerryGold1 11 ปีที่แล้ว

    Hi Gaven, I've got a lot out of your videos with my new RPi. Thanks! On this video, I think you forgot to show the first line which seems to be "import smtplib" When I added that to the script, everything worked great. Thanks!

  •  8 ปีที่แล้ว +1

    now its 2016 is this method still working for anyone i cant get it working :/

    • @hyperscitic92a
      @hyperscitic92a 8 ปีที่แล้ว +4

      Let guess...something about a non-zero status?
      If so, after digging A LOT I found that you have to go to your gmail account settings, click "connected apps & sites, then at the bottom enable the "allow less secure apps"
      Worked like a champ for me. Good luck!

    • @hyperscitic92a
      @hyperscitic92a 8 ปีที่แล้ว

      +mb34124 that's annoying I'm sure. I had the same issue as well but it turns out I had a misspelled word and missing a quotation mark. Double check your typing. Also note, sometimes the gmail servers may not be as quick as we would like. At times after running the script it would take 2-3+ minutes before the email would send.
      Sorry about your troubles, good luck.

    • @tiskolin
      @tiskolin 8 ปีที่แล้ว

      does not work for me... 2017 now and that is not a solution anymore. :( im trying to use a different third party mailing service.

    • @jlevym
      @jlevym 6 ปีที่แล้ว

      June 2018 - works perfectly from the command line once I did as suggested above : "Allow less secure apps: ON"
      thanks for the great Tutorial

  • @amineidrissi2073
    @amineidrissi2073 9 ปีที่แล้ว

    Thank you a lot

  • @MrTheben99
    @MrTheben99 8 ปีที่แล้ว

    Hello, what line should I add to send a file in my email?

    • @vincentcesca4901
      @vincentcesca4901 8 ปีที่แล้ว

      MrTheben99 echo "message content" | mail -s "subject" account@email.com -a file.zip

    • @D.Meanie
      @D.Meanie 8 ปีที่แล้ว

      is this line suppose to be in the terminal or in the python script?

  • @sandwichtube
    @sandwichtube 5 ปีที่แล้ว

    I got this to work by looking at the wiki. Google search for ssmtp wiki. Follow the instructions exactly. Make sure you save ssmtp.conf without spelling mistakes. It works for me without giving my host name. I opened port 25 on my cable modem but that might not have been a problem. This on a Raspberry Pi.

  • @onurazzlak
    @onurazzlak 7 ปีที่แล้ว

    How i can i conect this file with my motion sensor?

  • @updowndown
    @updowndown  11 ปีที่แล้ว

    Press ctrl-x to exit nano, which will give you a chance to save the file. Check out my video on running Python on the Raspberry Pi if you want to see a little more detail.

  • @sabarnachatterjee5918
    @sabarnachatterjee5918 5 ปีที่แล้ว

    Hi my requests library stopped working after this config. What I need to do?
    Error - Urllib3 not found

  • @JohnSmith-fb9mh
    @JohnSmith-fb9mh 10 ปีที่แล้ว

    how do I get motion to send a pic when motion is detected?

  • @azkikr316
    @azkikr316 7 ปีที่แล้ว

    Hi nice tutorial. how to send every most recent file. for example I have a temperature logs of a templogger.py that logs periodically and creating new file and I want to send the most recent logs created? thanks

  • @katefernandez240
    @katefernandez240 4 ปีที่แล้ว

    hi! can you help me how to add some codes in sending an image to the email? thank you :)

  • @Baxtexx
    @Baxtexx 8 ปีที่แล้ว

    When I try to send a mail from the terminal I get two errors: Cannot open mailer and cannot send message. But I do have installed SMTP and configured my account.

  • @antoniocarniero5138
    @antoniocarniero5138 5 ปีที่แล้ว

    Can you send files?

  • @thomasg3677
    @thomasg3677 9 ปีที่แล้ว

    Hello - I tried sending from python script and got this: File "piemail.py", line 11
    header = 'To: ' + toAdd + '
    ' + 'From: ' fromAdd + '
    ' + 'Subject: ' + subject
    I was wondering if you saw the syntax error - I cannot! Thanks for any help

  • @stevenbeebe35
    @stevenbeebe35 5 ปีที่แล้ว

    UPDATE: Google has some tough security measures. 1) Create a second account to play around with, you don't want your email to be nuked or destroyed or frozen. 2) Allow "less secure applications" to log into your account" with google settings. 3) Do not send out too many email messages, or google with think you are an email spam company and will freeze, block your account, don't overdue this. 4) Respond back to some of your own emails, so the spam filter won't think it is repetitive spam.

  • @synchrohd7synchrohd75
    @synchrohd7synchrohd75 5 ปีที่แล้ว

    Hi, looks cool, but how to attach a file i.e: a picture? Cheers.

  • @lostname605
    @lostname605 11 ปีที่แล้ว

    I always get an error in line 24: smtplib.SMTPException SMTP AUTH extension not supported by server.

  • @ShravanKumar-ru5kg
    @ShravanKumar-ru5kg 6 ปีที่แล้ว

    How to send an Image? could you please do a video on that please

  • @ianraspi8203
    @ianraspi8203 7 ปีที่แล้ว

    Great tutorial. I had to modify the port for it to work for me. To send from the shell, I had to use
    mailhub=smtp.gmail.com:465
    in the ssmtp.conf file.
    But in the python script, I had to use
    s = smtplib.SMTP('smtp.gmail.com',587)
    I don't know why though.

  • @kousoulides
    @kousoulides 11 ปีที่แล้ว

    The following packages have unmet dependencies:
    bind9-host : Depends: libbind9-80 (= 1:9.8.4.dfsg.P1-1) but it is not going to be installed
    Depends: libdns88 (= 1:9.8.4.dfsg.P1-1) but it is not going to be installed
    Depends: libisc84 (= 1:9.8.4.dfsg.P1-1) but it is not going to be installed
    Depends: libisccfg82 (= 1:9.8.4.dfsg.P1-1) but it is not going to be installed

  • @mriduljain1722
    @mriduljain1722 8 ปีที่แล้ว

    it is saying that mail command not found

  • @parthpatel20
    @parthpatel20 8 ปีที่แล้ว

    how can we attach image with mail??

    • @anandkrishnan72
      @anandkrishnan72 8 ปีที่แล้ว

      I would also like to know this. How would we attach images to the email.

  • @simons5660
    @simons5660 9 ปีที่แล้ว

    How do you Receive an email? please make a vider it would be very helpful. i couldn't find anything online on how to receive one.

  • @ThePanke66
    @ThePanke66 11 ปีที่แล้ว

    Thx, but my pi says 'Cannot open smtp.gmail.com:587

  • @justakidfromyaounde2830
    @justakidfromyaounde2830 2 ปีที่แล้ว

    Not working for me

  • @moscovita4
    @moscovita4 10 ปีที่แล้ว +4

    Thank you a lot for the video. The script was not working but then I just changed my settings for "enable less secure apps on the link below and got the email
    " www.google.com/settings/security/lesssecureapps"

  • @jvb-e4z
    @jvb-e4z 11 ปีที่แล้ว

    when I send the mail it appears 535, '5.7.8 Error authentification failed HELP PLEASE!!!

  • @utstra4
    @utstra4 11 ปีที่แล้ว

    Did all that was in that discussion, but didn't help... I just reinstalled Raspberian and everything worked fine :)

  • @chathuramadubashana9783
    @chathuramadubashana9783 10 ปีที่แล้ว

    Can you tel me how to upload a test file to a web server using pi?
    can you do a video tutorial on that. thank you

  • @bpac90
    @bpac90 8 ปีที่แล้ว

    Getting error. "mail: can not send message: Process exited with a non zero status." Any help anyone?

    • @hyperscitic92a
      @hyperscitic92a 8 ปีที่แล้ว +2

      I had the same issue. I found that you have to go to your gmail account settings, click "connected apps & sites, then at the bottom enable the "allow less secure apps"
      Worked like a champ for me. Good luck!

    • @ynzeselders4184
      @ynzeselders4184 8 ปีที่แล้ว

      Kyle Leser thankyou now I got it working

  • @KAFA2020
    @KAFA2020 7 ปีที่แล้ว

    Dear respected sir, Hope you are in good health with success and happiness.
    I'm facing a problem and not getting any solution. I'm trying to Configure Raspberry Pi Hardware to Mail IP Address Changes. But when I execute /etc/ssmtp/ssmtp.conf in Command Line session, It showing that -bash: /etc/ssmtp/ssmtp.conf : Permission denied
    PLEASE COULD YOU HELP ME how to solve the issue?

  • @MrRobbdog21
    @MrRobbdog21 10 ปีที่แล้ว

    send-mail: Authorization failed :(

  • @Cremejoghurt
    @Cremejoghurt 7 ปีที่แล้ว

    nice video dude. 2k17 and it works... at least for me

    • @DarkstarAcadia
      @DarkstarAcadia 7 ปีที่แล้ว

      do you know why the sudo apt-get install ssmtp mailutils is saying the the Url takes you to a 404 error and it couldn't fetch the file

    • @Cremejoghurt
      @Cremejoghurt 7 ปีที่แล้ว

      Sounds maby dumb but try sudo apt-get update first. This will update the database from where the Pi gets it's pakages. I copy pasted the command and hab absolutely no problems at all.

    • @Cremejoghurt
      @Cremejoghurt 7 ปีที่แล้ว

      Had not hab

  • @golfwarapun
    @golfwarapun 9 ปีที่แล้ว

    what is ?
    send-mail: Cannot open mailhub:25

  • @fp9359
    @fp9359 4 ปีที่แล้ว

    For anyone, who is having problem (cannot send message: Process exited with a non-zero status) visit. www.raspberrypi.org/forums/viewtopic.php?t=244147 this helped me. I hope, that it will help you too.

  • @greggod9186
    @greggod9186 4 ปีที่แล้ว

    This video is dated.

  • @jensenlloyd7632
    @jensenlloyd7632 5 ปีที่แล้ว

    how can we add a hyperlink inside a word for the body??

  • @Egonator2
    @Egonator2 8 ปีที่แล้ว

    thank you very much.

  • @julesindieu6084
    @julesindieu6084 7 ปีที่แล้ว

    How do I include a file in attachment?

  • @nuclearfission7868
    @nuclearfission7868 9 ปีที่แล้ว

    How do i stop cron from sending me error emails?