Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Gmail/Gmail_Send_email.ipynb
2973 views
Kernel: Python 3

Gmail.jpg

Gmail - Send email

Give Feedback | Bug report

Tags: #gmail #email #send #python #library #smtplib

Last update: 2023-05-12 (Created: 2023-05-12)

Description: This notebook will show how to send an email using naas_drivers. It is usefull for organizations that need to send emails from their Gmail account.

Input

Import libraries

import naas from naas_drivers import email

Setup Variables

Create an application password following this procedure

  • username: This variable stores the username or email address associated with the email account

  • password: This variable stores the password or authentication token required to access the email account

  • smtp_server: This variable represents the SMTP server address used for sending emails.

  • box: This variable stores the name or identifier of the mailbox or folder within the email account that will be accessed.

  • email_to: This variable stores the email receiver address.

  • email_subject: This variable stores the email subject.

  • email_msg: This variable stores the email msg.

# Inputs username = "xxxxx@xxxxx" password = naas.secret.get("GMAIL_APP_PASSWORD") or "xxxxxxxx" smtp_server = "imap.gmail.com" box = "INBOX" # Outputs email_to = "xxxxx@xxxxx" email_subject = "My First Email" email_msg = "This is a test email"

Model

Connect to email box

emails = email.connect(username, password, smtp_server=smtp_server)

Output

Send email

emails.send( email_to=email_to, subject=email_subject, content=email_msg )