Skip to content

Commit

Permalink
RPA.Cloud.Google. Add possibility to send HTML email (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikahanninen authored Sep 14, 2023
1 parent d78d727 commit 958bff9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/source/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Latest versions
`Released <https://pypi.org/project/rpaframework/#history>`_
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

14 Sep 2023
-----------

- Library **RPA.Cloud.Google** (:pr:`1092`; ``rpaframework-google`` **8.1.0**): Add
possibility to send HTML email by adding `html` parameter for ``Send Message``
keyword.

27.0.1 - 11 Sep 2023
--------------------

Expand Down
2 changes: 1 addition & 1 deletion packages/google/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rpaframework-google"
version = "8.0.0"
version = "8.1.0"
description = "Google library for RPA Framework"
authors = ["RPA Framework <[email protected]>"]
license = "Apache-2.0"
Expand Down
12 changes: 10 additions & 2 deletions packages/google/src/RPA/Cloud/Google/keywords/gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,25 @@ def create_message(
subject: str,
message_text: str,
attachments: list = None,
html: bool = False,
):
"""Create a message for an email.
:param to: message recipient
:param subject: message subject
:param message_text: message body text
:param attachment: list of files to add as message attachments
:param html: set to True if message body is HTML (default False, plain text)
:return: An object containing a base64url encoded email object
"""
mimeMessage = MIMEMultipart()
mimeMessage["to"] = to
mimeMessage["subject"] = subject
mimeMessage.attach(MIMEText(message_text, "plain"))

if html:
mimeMessage.attach(MIMEText(message_text, "html"))
else:
mimeMessage.attach(MIMEText(message_text, "plain"))

for at in attachments:
self.add_attachment_to_message(mimeMessage, at)
Expand Down Expand Up @@ -135,6 +141,7 @@ def send_message(
subject: str,
message_text: str,
attachments: list = None,
html: bool = False,
):
"""Send an email message.
Expand All @@ -143,6 +150,7 @@ def send_message(
:param subject: message subject
:param message_text: message body text
:param attachment: list of files to add as message attachments
:param html: set to True if message body is HTML (default False, plain text)
:return: sent message
Example:
Expand All @@ -161,7 +169,7 @@ def send_message(
if not self.service:
raise AssertionError("Gmail service has not been initialized")
attachments = attachments or []
message = self.create_message(to, subject, message_text, attachments)
message = self.create_message(to, subject, message_text, attachments, html)
try:
response = (
self.service.users()
Expand Down

0 comments on commit 958bff9

Please sign in to comment.