0

For a project I'm trying to take a photo using a camera connected to my raspberry pi after pressing a button and then sending the photo taken using Gmail.

So far, all I've figured out is how to take the photo after pressing the button (see the code), but I still haven't figured out how to send an email with the photo after taking the photo. By the way, I want the photo being taken and the email being sent done in only one button press. Also, I'm using IDLE python 3.

from gpiozero import Button
from picamera import PiCamera
from signal import pause

import time

camera = PiCamera()

def take_picture_with_camera():

    image_path = 'blahblah.jpg'
    camera.capture(image_path)
    print('Took photo')

button = Button(4)
button.when_pressed = take_picture_with_camera

pause()
petezurich
  • 9,280
  • 9
  • 43
  • 57
  • Sorry about the messed up code, only second time asking on stackoverflow! – Jason Lee Jun 01 '19 at 09:45
  • Try sending a text email first, and then try to send an HTML email with the photo encoded in base64. Check out mailgun.org if you want to learn how to send email programatically to 'normal' email providers like GMail. – dg-vwp Jun 01 '19 at 09:48

1 Answers1

0

The smtplib provides you with email functionality. You can just add the email sender into the button trigger. The topic of adding attachments has been discussed, f.e. here:

How to send email attachments?

Richard Nemeth
  • 1,784
  • 1
  • 6
  • 16