Skip to main content

GMail Bot API

Project description

AndEggs

AndEggs is a Python library that allows you to create an email bot using Gmail's API.

Simple Documentation

Client Class

The Client class will be the main entry point of your program.

Create a Client

First, create a new client by calling the Client constructor:

    >>> from andeggs import Client
    >>> client = Client('CommandPrefix')

Then, you can use the Client object to interact with Gmail's API.

Creating a Command

To create a command, you should create an asynchronous function that will be called when the command is triggered. It should take in a MailContext object as its only parameter. This object contains all the information about the email that triggered the command. To turn it into a command, use the Client.command decorator:

    >>> @client.command('CommandName')
    >>> async def command(context: MailContext):
    >>>     # Do something
    >>>     pass

Sending an Email

To send an email, you should use the Client.send method:

    >>> client.send(
    >>>     to='RecipientEmail',
    >>>     subject='Subject',
    >>>     body='Body',
    >>>     is_html=False,
    >>> )

Activating the Client

To activate the client, you should call the Client.run method:

    >>> client.run('youremail', 'yourpassword')

Events

Events are triggered when certain actions happen. Below is a list of the events that can be triggered and their parameters:

  • on_ready: Triggered when the client is started.
  • on_message: Triggered when a new email is received. The parameter is a MailContext object.
  • on_send: Triggered when an email is sent. The parameter is a MailContext object.
  • on_command: Triggered when a command is triggered. The parameter is a MailContext object.
  • on_stop: Triggered when the client is stopped.

Tasks

A task is a function that runs in the background. You can use the Client.task decorator to create a task:

    >>> @client.task(interval=60)
    >>> async def task():
    >>>     # Do something
    >>>     pass

MailContext

On all of your commands, you will receive a MailContext object. This object contains all the information about the email that triggered the command.

Attributes

  • sender: A Sender object.
  • subject: The subject of the email.
  • body: The body of the email.

Sending an Email

You can also send an email using the MailContext.send method:

    >>> context.send(
    >>>     'Body',
    >>> )

If you want to format your text with html, you should use the MailContext.sendf method:

    >>> context.sendf(
    >>>     '<p>{}</p>',
    >>>     'Body',
    >>> )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

and_eggs-0.0.7-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page