I've been working with the Mutt mail client for a while and trying to implement it in my Python script but something is giving me an error. First tell you that I have it configured well and that I can send e-mails from the console with the command:
echo "Mensaje" | mutt -s "Asunto" [email protected]
But I'm trying to implement this in a Python script that I need to send a photo by mail and I'm not able, the code is this:
fecha = time.strftime("%d%m%Y-%H%M%S") # En esta variable se guarda la fecha actual y la hora para renombrar la foto guardada
camera.capture('/home/pi/Desktop/RaspAlarm/Fotos/{}.jpg'.format(fecha))
print("Capturando foto")
time.sleep(2)
print("Foto guardada")
print("Enviando foto")
os.system('echo "La alarma ha sido activada {}" .format(fecha) | mutt -s "Alguien a abierto la puerta" [email protected] -a /home/pi/Desktop/RaspAlarm/Fotos/{}.jpg .format(fecha)')
print("Foto enviada con exito")
The program does not give me any errors but it does not send the mail. I do not know if you can not use mutt within Python, or if there is some other way to send an email. I have seen that there are specific smtp libraries but I have seen it easier to use mutt although I do not know if it is possible.
Thanks in advance!