gmail-api-client 0.1.0__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gmail-api-client
3
- Version: 0.1.0
3
+ Version: 0.1.3
4
4
  Summary: A simple Python client for Gmail API automation
5
5
  Author: Asheesh Singh
6
6
  License: MIT
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "gmail-api-client"
8
- version = "0.1.0"
8
+ version = "v0.1.3"
9
9
  description = "A simple Python client for Gmail API automation"
10
10
  readme = "README.md"
11
11
  requires-python = ">=3.9"
@@ -1,6 +1,8 @@
1
1
  import base64
2
2
  import os
3
3
  from email.message import EmailMessage
4
+ from email import policy
5
+ from html import escape
4
6
  from typing import Optional
5
7
 
6
8
  from google.auth.transport.requests import Request
@@ -81,9 +83,9 @@ class GmailClient:
81
83
  ) -> EmailMessage:
82
84
  """Create an email message."""
83
85
 
84
- message = EmailMessage()
85
-
86
- message.set_content(body)
86
+ message = EmailMessage(
87
+ policy=policy.SMTP
88
+ )
87
89
 
88
90
  if sender:
89
91
  message["From"] = sender
@@ -91,6 +93,23 @@ class GmailClient:
91
93
  message["To"] = to
92
94
  message["Subject"] = subject
93
95
 
96
+ # Plain-text fallback
97
+ message.set_content(body)
98
+
99
+ # HTML version
100
+ html_body = f"""
101
+ <html>
102
+ <body>
103
+ <p>{escape(body)}</p>
104
+ </body>
105
+ </html>
106
+ """
107
+
108
+ message.add_alternative(
109
+ html_body,
110
+ subtype="html",
111
+ )
112
+
94
113
  return message
95
114
 
96
115
  @staticmethod
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gmail-api-client
3
- Version: 0.1.0
3
+ Version: 0.1.3
4
4
  Summary: A simple Python client for Gmail API automation
5
5
  Author: Asheesh Singh
6
6
  License: MIT
@@ -34,7 +34,21 @@ def test_create_message():
34
34
 
35
35
  assert message["To"] == "recipient@example.com"
36
36
  assert message["Subject"] == "Test Subject"
37
- assert message.get_content().strip() == "Test Body"
37
+
38
+ assert message.get_content_type() == "multipart/alternative"
39
+
40
+ parts = message.get_payload()
41
+
42
+ assert len(parts) == 2
43
+
44
+ plain_part = parts[0]
45
+ html_part = parts[1]
46
+
47
+ assert plain_part.get_content_type() == "text/plain"
48
+ assert html_part.get_content_type() == "text/html"
49
+
50
+ assert plain_part.get_content().strip() == "Test Body"
51
+ assert "Test Body" in html_part.get_content()
38
52
 
39
53
 
40
54
  def test_create_message_with_sender():