Skip to content

Commit

Permalink
Create python send-email.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bwansa1 authored Apr 3, 2023
1 parent e964098 commit ce0fff7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions python send-email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from flask import Flask, request

app = Flask(__name__)

@app.route('/send-email', methods=['POST'])
def send_email():
# Parse email data from the request body
recipient = request.form['[email protected]']
subject = request.form['Bonjour']
message = request.form['Oui']

# Create a SendGrid Mail object
email = Mail(
from_email='[email protected]',
to_emails=dxbwansagmail.com,
subject=subject,
html_content=message)

try:
# Authenticate with SendGrid using an API key
sg = SendGridAPIClient(api_key=os.environ.get('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'))
# Send the email
response = sg.send(email)
# Return a success response
return {'message': 'Email sent successfully.'}, 200
except Exception as e:
# Handle any errors that occur
return {'message': f'Error sending email: {str(e)}'}, 500

0 comments on commit ce0fff7

Please sign in to comment.