Git Product home page Git Product logo

chalice-mail's Introduction

One of the most basic functions in a web application is the ability to send emails to your users fully serverlessly.

Downloads

Downloads Downloads Downloads

Maintainers wanted

Chalice-Mail

The Chalice-Mail extension provides a simple interface to set up SMTP and AWS SES(Simple Email Service) with your Chalice application and to send messages from your views and scripts. source code available at: Github Repo

Usage

Using SMTP => TLS Encryption
from chalice import Chalice
from chalice_mail import Mail, Message

app = Chalice(app_name='chalice-mail-test1')
mail = Mail(app)
mail.is_smtp = True
mail.smtp_using_tls = True
mail.username = "[email protected]"
mail.password = "world's_top_secret_password"
mail.smtp_server = 'smtp.example.com'
mail.smtp_port = 587
mail.login()

@app.route('/send-smtp-mail')
def send_smtp_mail():
    msg = Message(mail)
    msg.subject = "this is the subject"
    msg.add_recipient("[email protected]")
    msg.plain = "This is the email body."
    mail.send_email(msg)
    return {'message':'email sended successfully'}
Using SMTP => SSL Encryption
from chalice import Chalice
from chalice_mail import Mail, Message

app = Chalice(app_name='chalice-mail-test1')
mail = Mail(app)
mail.is_smtp = True
mail.smtp_using_ssl = True
mail.username = "[email protected]"
mail.password = "world's_top_secret_password"
mail.smtp_server = 'smtp.example.com'
mail.smtp_port = 465
mail.login()

@app.route('/send-smtp-mail')
def send_smtp_mail():
    msg = Message(mail)
    msg.subject = "this is the subject"
    msg.add_recipient("[email protected]")
    msg.plain = "This is the email body."
    mail.send_email(msg)
    return {'message':'email sended successfully'}
Using SES(Simple Email Service)
from chalice import Chalice
from chalice_mail import Mail, Message

app = Chalice(app_name='chalice-mail-test1')
mail = Mail(app)
mail.username = "[email protected]"
mail.aws_region = "ap-south-1"
"""
please provide the value of 'mail.aws_secret_id' 
and 'mail.aws_secret_key' if you want to set the AWS 
Iam user manually.
"""
mail.login()

@app.route('/send-smtp-mail')
def send_smtp_mail():
    msg = Message(mail)
    msg.subject = "this is the subject"
    msg.add_recipient("[email protected]")
    msg.plain = "This is the email body."
    mail.send_email(msg)
    return {'message':'email sended successfully'}
Using SMTP => Email with HTML
from chalice import Chalice
from chalice_mail import Mail, Message

app = Chalice(app_name='chalice-mail-test1')
mail = Mail(app)
mail.is_smtp = True
mail.smtp_using_tls = True
mail.username = "[email protected]"
mail.password = "world's_top_secret_password"
mail.smtp_server = 'smtp.example.com'
mail.smtp_port = 587
mail.login()

@app.route('/send-smtp-mail')
def send_smtp_mail():
    msg = Message(mail)
    msg.subject = "this is the subject"
    msg.add_recipient("[email protected]")
    """ 
    Simply pass the html value to the html variable of Message instance.
    """
    msg.html = "<h1>This is the email body.</h1>"
    mail.send_email(msg)
    return {'message':'email sended successfully'}
Using SMTP => Email with HTML rendering
from chalice import Chalice
from chalice_mail import Mail, Message
from pathlib import Path
from os import path

app = Chalice(app_name='chalice-mail-test1')
_baseDir = Path(path.realpath(__file__)).parent
mail = Mail(app)
mail.is_smtp = True
mail.smtp_using_tls = True
mail.username = "[email protected]"
mail.password = "world's_top_secret_password"
mail.smtp_server = 'smtp.example.com'
mail.smtp_port = 587
mail.template_dir = _baseDir/'templates' # required if using template rendering.
mail.login()

@app.route('/send-smtp-mail')
def send_smtp_mail():
    msg = Message(mail)
    msg.subject = "this is the subject"
    msg.add_recipient("[email protected]")
    context={}
    """
    This package comes with the jinja2 based template rendering system.
    Simpley use the 'render_template()' function to rend the html file.
        'render_template()' functions takes the html file name as arguments 
    and the context as well as.
    """
    msg.html = mail.render_template('index.html', context)
    mail.send_email(msg)
    return {'message':'email sended successfully'}
Using SMTP => Email with attachments
from chalice import Chalice
from chalice_mail import Mail, Message
from pathlib import Path
from os import path

app = Chalice(app_name='chalice-mail-test1')
_baseDir = Path(path.realpath(__file__)).parent
mail = Mail(app)
mail.is_smtp = True
mail.smtp_using_tls = True
mail.username = "[email protected]"
mail.password = "world's_top_secret_password"
mail.smtp_server = 'smtp.example.com'
mail.smtp_port = 587
mail.attachment_dir = _baseDir/'attachments' # required if using attachments.
mail.login()

@app.route('/send-smtp-mail')
def send_smtp_mail():
    msg = Message(mail)
    msg.subject = "this is the subject"
    msg.add_recipient("[email protected]")
    msg.plain = "This is the email body."
    """
    Use the 'add_attachments()' function to add the attachments 
    with the message instance. Don't forget to put the attachments 
    on the attachments folder.
        'add_attachments()' function basically takes list or str data 
    type as argument. If you want to add only one attachment just pass 
    the attachment name. If you want to add more than one attachments use a list.
    """
    msg.add_attachments(['python.png', 'README.rst'])
    mail.send_email(msg)
    return {'message':'email sended successfully'}

Installation

chalice-mail is available from pypi.

install using pip

pip install chalice-mail

install from source code

git clone https://github.com/marktennyson/chalice-mail && cd chalice-mail
python setup.py install --user

Compatibility

chalice-mail is compatiable with python3.6 and higher versions. Not compatiable for Python version 2.

Contributing

We welcome contributions of all types!

chalice-mail's People

Contributors

marktennyson avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

chalice-mail's Issues

Doesn't work anymore.

The package versions that are needed are incompatible with most other things in a normal python environment. So it is impossible to satisfy the requirements and hence this lib doesn't work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.