Closed contactsystemtt closed 9 hours ago
I haven't implemented the ability to send attachments yet. But if you want to insert a photo, you can paste a link to it, or base64 encode it, although not all mails will allow you to see the photo (protonmail will show it, gmail will not)
from base64 import b64encode
with open('image.png', 'rb') as f:
img = f.read()
html = f"""
<div>
<img src="https://raw.githubusercontent.com/opulentfox-29/protonmail-api-client/master/assets/1.png" height="150" width="300" alt="image.png">
<br/>
<img src="data:image/png;base64, {b64encode(img).decode()}" height="150" width="300" alt="image.png">
</div>
"""
new_message = proton.create_message(
recipients=['to1@proton.me'],
subject='hello',
body=html,
)
message = proton.send_message(new_message, is_html=True)
You can now send attachments and insert pictures into letter.
# Create attachments
with open('image.png', 'rb') as f:
img = f.read()
with open('resume.pdf', 'rb') as f:
pdf = f.read()
img_attachment = proton.create_attachment(content=img, name='image.png')
pdf_attachment = proton.create_attachment(content=pdf, name='resume.pdf')
html = f"""
<html>
<body>
<h2>Hi, I'm a python developer, here's my photo:</h2>
<img {img_attachment.get_embedded_attrs()} height="150" width="300">
<br/>
Look at my resume, it is attached to the letter.
</body>
</html>
"""
# Send message
new_message = proton.create_message(
recipients=["to1@proton.me", "to2@gmail.com"],
subject="My first message",
body=html, # html or just text
attachments=[img_attachment, pdf_attachment],
)
sent_message = proton.send_message(new_message)
I want to add an attachment when sending a mail.... I tried the following code