Hello all I'm trying to send a very basic email to myself using my raspberry pi and a sim800l module... however, it cannot send a basic message to myself. I've used it with an arduino so I know that the module is okay but cannot seem to get the rest working. Please help
import RPi.GPIO as GPIO
import smtplib, datetime, os, time, serial
# EMAIL - - - - -
USERNAME = 'user@gmail.com' # Username for authentication
PASSWORD = 'pass' # Password for authentication
SMTP_SERVER = "smtp.gmail.com" # URL of SMTP server
SSL_PORT = 465 #message sumbmission over TLS protocal
FROM = "from@gmail.com" # Name shown as sender
TO = 'recp@gmail.com' # Mail address of the recipient
NAME = 'patrick bateman'
# SIM800L - - - - -
cmd=''
ser = serial.Serial('/dev/serial0', 9600, timeout=2)
ser.reset_input_buffer()
def setup():
GPIO.setmode(GPIO.BOARD)
# GPIO.setup(P_BUTTON, GPIO.IN, GPIO.PUD_UP)
def sendCommand(command):
smd= command
smd=smd+'\r\n'
smds=smd.encode('ascii')
ser.write(smds)
time.sleep(1)
line = ser.read(80).decode('ascii').rstrip()
print(line)
def sendMail(subject, text, img = None):
print("initilizing")
def checkSystemIsFullyOpperational():
sendCommand('AT') #check that you can get a response form SIM module
sendCommand('AT+CMEE=2')
sendCommand('AT+CPIN?') # checks
sendCommand('AT+CSQ') # checks signal strength. col 1: 31 is bet, 0 worst.
# 99 means you don't have a connection.
sendCommand('AT+CGREG?') # Checks if device is regestered to a network. Want "0,1"
checkSystemIsFullyOpperational()
sendCommand('AT')
sendCommand('AT+SAPBR=3,1,"Contype","GPRS"') # Configure bearer profile 1
sendCommand('AT+EMAILCID=1') # Set paramaters of Email
#sendCommand('AT+EMAILTO=30') # Timeout for server response (defult 30 secs)
sendCommand('AT+SMTPSRV="{}","{}"'.format(SMTP_SERVER, SSL_PORT)) # Set SMTP server address and port
sendCommand('AT+SMTPAUTH=1,"{}",{}'.format(USERNAME,PASSWORD)) # Set username and password.
sendCommand('AT+SMTPFROM="{}",{}'.format(USERNAME,FROM)) # Set sender address and name
sendCommand('AT+SMTPRCPT=0,0,"{}",{}'.format(TO,NAME)) # Set the recipients name
sendCommand('AT+SMTPSUB="{}"'.format("This is sent from the rapsberry pi")) # Body of text
sendCommand('AT+SMTPSEND')