idutchy / gmailpy Goto Github PK
View Code? Open in Web Editor NEWAn API wrapper for Gmail
License: MIT License
An API wrapper for Gmail
License: MIT License
I edited the code a bit to fix it.
import smtplib
import ssl
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
class Error(Exception):
pass
class Client:
def __init__(self, mail, password):
self.mail = mail
self.password = password
async def send(self, receiver, body, subject=None, bcc=None, attachment_bytes=None, attachment_name=None):
sender_email = self.mail
password = self.password
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver
message["Subject"] = subject if subject else "No subject"
message["Bcc"] = bcc
message.attach(MIMEText(body, "plain"))
if attachment_name is None and attachment_bytes is not None:
raise Error('You did not provide an attachment name for your attachment!')
if attachment_name is not None and attachment_bytes is None:
raise Error('Can not set an attachment name without an attachment!')
if attachment_bytes is not None and attachment_name is not None:
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment_bytes)
encoders.encode_base64(part)
part.add_header(
"Content-Disposition",
f"attachment; filename= {attachment_name}",
)
message.attach(part)
text = message.as_string()
server = smtplib.SMTP(host="smtp.gmail.com", port=587)
server.starttls()
server.login(sender_email, password)
server.sendmail(sender_email, receiver, text)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.