Skip to content

Commit 5e2b619

Browse files
committed
Update send email
1 parent 45108f4 commit 5e2b619

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

patchwork/steps/SendEmail/SendEmail.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import imaplib
4+
import poplib
35
import smtplib
46
from email.mime.text import MIMEText
57

@@ -16,10 +18,12 @@ def __init__(self, inputs):
1618
self.body = inputs.get("body", "Patchwork Execution Email")
1719
self.sender_email = inputs["sender_email"]
1820
self.recipient_email = inputs["recipient_email"]
19-
self.password = inputs["sender_email_password"]
2021
self.smtp_host = inputs.get("smtp_host", "smtp.gmail.com")
21-
self.smtp_port = int(inputs.get("smtp_port", 465))
22+
self.smtp_username = inputs["smtp_username"]
23+
self.smtp_password = inputs["smtp_password"]
24+
self.smtp_port = int(inputs.get("smtp_port", 25))
2225
self.reply_message_id = inputs.get("reply_message_id")
26+
self.is_ssl = bool(inputs.get("is_smtp_ssl", False))
2327

2428
def run(self) -> dict:
2529
msg = MIMEText(mustache_render(self.body, self.email_template_value))
@@ -30,9 +34,12 @@ def run(self) -> dict:
3034
msg.add_header("Reference", self.reply_message_id)
3135
msg.add_header("In-Reply-To", self.reply_message_id)
3236

33-
# TODO: support smtp without ssl
34-
with smtplib.SMTP_SSL(self.smtp_host, self.smtp_port) as smtp_server:
35-
smtp_server.login(self.sender_email, self.password)
36-
smtp_server.sendmail(self.sender_email, self.recipient_email, msg.as_string())
37+
smtp_clazz = smtplib.SMTP
38+
if self.is_ssl:
39+
smtp_clazz = smtplib.SMTP_SSL
40+
41+
with smtp_clazz(host=self.smtp_host, port=self.smtp_port) as mailserver:
42+
mailserver.login(self.smtp_username, self.smtp_password)
43+
mailserver.sendmail(self.sender_email, self.recipient_email, msg.as_string())
3744

3845
return dict()

patchwork/steps/SendEmail/typed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
class __SendEmailRequiredInputs(TypedDict):
55
sender_email: str
66
recipient_email: str
7-
sender_email_password: str
7+
smtp_username: str
8+
smtp_password: str
89

910

1011
class SendEmailInputs(__SendEmailRequiredInputs, total=False):
@@ -14,6 +15,7 @@ class SendEmailInputs(__SendEmailRequiredInputs, total=False):
1415
smtp_host: str
1516
smtp_port: int
1617
reply_message_id: str
18+
is_smtp_ssl: str
1719

1820

1921
class SendEmailOutputs(TypedDict):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "patchwork-cli"
3-
version = "0.0.99.dev5"
3+
version = "0.0.99.dev6"
44
description = ""
55
authors = ["patched.codes"]
66
license = "AGPL"

0 commit comments

Comments
 (0)