Skip to main content

Learn more and get the facts

Keep up to date with the latest information

Links to useful resources

Access the latest industry news and resources

We strive to stay up to date with the latest industry resources, news, and insights. Read more about them below.

Let's talk

We would love to hear from you!

Title

This text is where you can provide website visitors with instructions on how to use the app in your section.

Visitors often appreciate knowing what to expect when they click on an app and are more likely to click if you tell them the value associated with taking that action.

Chat with API

Chat Interface

Response:

  • import os from flask import Flask, request, render_template, redirect, url_for from flask_mail import Mail, Message from werkzeug.utils import secure_filename app = Flask(__name__) # Configurations for Flask-Mail app.config['MAIL_SERVER'] = 'smtp.office365.com' app.config['MAIL_PORT'] = 587 app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME') app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD') app.config['MAIL_USE_TLS'] = True app.config['MAIL_USE_SSL'] = False mail = Mail(app) # Directory to save uploaded files temporarily UPLOAD_FOLDER = '/path/to/the/uploads' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: return redirect(request.url) file = request.files['file'] # If the user does not select a file, the browser submits an # empty file without a filename. if file.filename == '': return redirect(request.url) if file: filename = secure_filename(file.filename) filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) file.save(filepath) send_email_with_attachments(filepath) return 'Email sent!' return render_template('index.html') def send_email_with_attachments(filepath): msg = Message('Hello from Flask', sender=app.config['MAIL_USERNAME'], recipients=['andrew@365capital.us']) msg.body = 'This email contains attachments sent from Flask.' with app.open_resource(filepath) as fp: msg.attach(filename=filepath, content_type='application/octet-stream', data=fp.read()) mail.send(msg) if __name__ == '__main__': app.run(debug=True)