Closed rauldpm closed 1 year ago
Steps to send emails
apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_use_tls = yes
echo [smtp.gmail.com]:587 email:app_password > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
chmod 400 /etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
systemctl reload postfix
echo "Test mail from postfix" | mail -s "Test Postfix" -r "you@example.com" you@example.com
code = str(random.randint(100000,999999))
port = 587
server = "smtp.gmail.com"
sender = sender
recipient = reserva_email
password = "APP_PASSWORD"
msg = MIMEMultipart()
message = "Hello!\n"
message += "Your reservation code is: " + code
msg['From'] = sender
msg['To'] = recipient
msg['Subject'] = "Restaurant reservation code"
msg.attach(MIMEText(message, "plain"))
text = msg.as_string()
SSLcontext = ssl.create_default_context()
with smtplib.SMTP(server, port) as server:
server.starttls(context=SSLcontext)
server.login(sender, password)
server.sendmail(sender, recipient, text)
This issue aims to add a confirmation via email of the reservation made by the user. This could be done by asking the user for a contact email where to send a summary of the reservation using postman.