Giter Club home page Giter Club logo

bergamot's Introduction

bergamot

An email manager for Tangerine

heres a general idea for the class

import re
import smtplib

class Bergamot:
    def __init__(self, email, password):
        self.email = email
        self.password = password

        self.servers = {
            'gmail': {
                'smtp_server': 'smtp.gmail.com',
                'port': 587
            },
            'yahoo': {
                'smtp_server': 'smtp.mail.yahoo.com',
                'port': 465
            },
            'hotmail': {
                'smtp_server': 'smtp.live.com',
                'port': 587
            }
        }

    def send_email(self, recipient, message):
        # Use regex to determine the email provider
        match = re.search('@(\w+)', recipient)
        if not match:
            raise ValueError('Invalid recipient email')
        provider = match.group(1)

        # Get the smtp server and port based on the email provider
        if provider in self.servers:
            server_info = self.servers[provider]
            smtp_server = server_info['smtp_server']
            port = server_info['port']
        else:
            raise ValueError('Unsupported email provider')

        # Try to send the email
        try:
            server = smtplib.SMTP(smtp_server, port)
            server.starttls()
            server.login(self.email, self.password)

            subject = 'Hello from Bergamot!'
            body = f'This message was sent from Bergamot: {message}'
            message = f'Subject: {subject}\n\n{body}'

            server.sendmail(self.email, recipient, message)

            return f'Email sent to {recipient}!'
        except:
            raise ValueError('Failed to send email')

Here's how you would use it.

from tangerine import Tangerine, Router
from bergamot import Bergamot

tangerine = Tangerine()
router = Router()

bergamot = Bergamot('[email protected]', 'yourpassword')

router.post('/send-email', lambda ctx:
    try:
        message = ctx.req.form.get('message')
        recipient = ctx.req.form.get('recipient')
        result = bergamot.send_email(recipient, message)
        ctx.body = result
        ctx.send(200)
    except ValueError as e:
        ctx.body = str(e)
        ctx.send(400)
)

tangerine.use(router)

if __name__ == '__main__':
    tangerine.start()

bergamot's People

Contributors

noraa-july-stoke avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.