How do I send an email in flask from porkbun?

42 views Asked by At
from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)
mail = Mail(app)

# Configuration of mail
app.config['MAIL_SERVER'] = 'smtp.porkbun.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USERNAME'] = '[email protected]'  # Replace with your actual email address
app.config['MAIL_PASSWORD'] = '****'  # Replace with your actual email password
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False

mail = Mail(app)

# Message object mapped to a particular URL ‘/’
@app.route("/")
def index():
    msg = Message(
        'Hello from Flask-Mail',
        sender='[email protected]',
        recipients=['[email protected]']  # Replace with the recipient's email address
    )
    msg.body = 'Hello Flask message sent from Flask-Mail'
    try:
        mail.send(msg)
        return 'Email sent successfully!'
    except Exception as e:
        return f'Error sending email: {str(e)}'


if __name__ == '__main__':
    app.run(debug=True)

I am trying to send an email from a porkbun hosted email service, and I'm trying to use flask-mail to do so. When I visit localhost/ I get the message "email sent successfully" but I dont receive the email and there are no errors. I don't really know what to do, can anyone help? (All of the emails and passwords are **** or [email protected])

0

There are 0 answers