Smtplib is not triggering mail for multiple trigger at same time
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginne mit der Überprüfung des Celery-Task-Codes und von email_notification.py, insbesondere von _email_notification und dem smtplib-sendmail-Pfad. Reproduziere die gleichzeitige Task-Ausführung und prüfe, ob jeder Task sendmail erreicht und ob Ausnahmen gemeldet werden; abgeschlossen ist die Aufgabe, wenn die Ursache der fehlenden Nachrichten identifiziert und ein fokussierter Regressionstest oder eine klare Reproduktion hinzugefügt wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Celery tasks:
`celeryApp = Celery(
"celerytasks", broker="pyamqp://localhost//", timezone="Canada/Eastern"
)
@celeryApp.on_after_configure.connect
def setup_periodic_tasks(sender, **kwargs):
# celery beats setup
notification = Notification.get_all_notification()
print("Celery Initiated")
for notify in range(len(notification)):
# Creating worker task for every notification
notify_time = notification_time(notification["time"][notify])
# scheduling perioding task based notification table
result = sender.add_periodic_task(
notify_time,
defect_task_call.s(
str(notification["id"][notify]),
notification["defect"][notify],
notification["email"][notify],
notification["time"][notify],
notification["condition"][notify],
str(notification["value"][notify]),
notification["line"][notify],
notification["directory"][notify],
),
name=notification["id"][notify],
)
@celeryApp.task(name="alert")
def defect_task_call(
id: str,
defect_type: str,
receiver_email: str,
time: str,
condition: str,
value: str,
line: str,
directory: str,
):
"""Worker Task based on every notification
Args:
id: str, -> ID of the notification
defect_type: str,
receiver_email: str, -> Notification reciever
time: str, -> time schedule
condition: str,
value: str,
line: str,
directory: str, -> Directory recived
Returns:
condition :str
"""
value = int(value)
# print("TaskID ",celeryApp.task.id)
print("Wrk ID", celeryApp.current_worker_task.request.id)
print(defect_type)
print(id)
# Hourly or minute check
if "M" in time:
parts = Part.get_last_n_minute_types(
line_sub_id=line,
minute=parts_time(time),
defect=defect_type,
approved=True,
)
if "H" in time:
parts = Part.get_last_n_hour_types(
line_sub_id=line,
hour=parts_time(time),
defect=defect_type,
approved=True,
)
if parts.empty:
alert = notification_condition(condition, parts.count()["Defect Type"], value)
# email notification for alerts
if alert == True:
mail_subject = (
"Alert Mail for Defect Type: "
+ str(defect_type).replace("_", " ").title()
)
body_content = (
"Threshold reached alert of Defect: ' "
+ str(defect_type).replace("_", " ").title()
+ " '"
)
table_content = (
"""
<tr>
<th>Defect Type</th>
<th>Time Period</th>
<th>Current Count</th>
<th>Condition</th>
<th>Alert Value</th>
<th>Directory</th>
<th>Line</th>
</tr>
<tr>
<td>"""
+ str(defect_type).replace("_", " ").title()
+ """</td>
<td>"""
+ email_time(time)
+ """</td>
<td>"""
+ str(parts.count()["Defect Type"])
+ """</td>
<td>"""
+ email_condition(condition)
+ """</td>
<td>"""
+ str(value)
+ """</td>
<td>"""
+ directory
+ """</td>
<td>"""
+ line
+ """</td>
</tr>
"""
)
email_notification._email_notification(
mail_subject=mail_subject,
body_content=body_content,
receiver_email=receiver_email,
table_content=table_content,
)
print("Mail Sent")`
email_notification.py
`def _email_notification(
mail_subject: str, body_content: str, receiver_email: str, table_content=""
):
"""Function snds mail to reciever mail ids
Args:
mail_subject: str,
body_content: str,
receiver_email: str,
table_content: table contents
"""
Mail_subject = "Testing Cendiant Mail Bot"
if mail_subject != "":
Mail_subject = mail_subject
Body_content = "I'm Cendiant, The Mail Bot."
if body_content != "":
Body_content = body_content
body = (
"""
<html>
<head>
<style>
#mail {
width: 70%;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<div id="mail">
<b><i>Hi There,</i></b><br>
"""
+ Body_content
+ """<br>
<br>
<table>
"""
+ table_content
+ """
</table>
<br><br>
Thank you<br>
</div>
</body>
</html>
"""
)
email_port = config["email"]["port"]
email_domain = config["email"]["domain"]
email_id = config["email"]["sender"]
app_password = config["email"]["app_password"]
Receiver_email = config["email"]["sender"]
if receiver_email != "":
Receiver_email = receiver_email
email_server = smtplib.SMTP(email_domain, email_port)
email_content = MIMEMultipart("alternative")
email_content["Subject"] = Mail_subject
email_body = MIMEText(body, "html")
email_content.attach(email_body)
email_server.starttls()
email_server.login(email_id, app_password)
# Sending Email
try:
time.sleep(5)
email_server.sendmail(email_id, Receiver_email, email_content.as_string())
email_server.quit()
except Exception as es:
print(str(es))`
Issue:
Some mails are not triggered by smtplib
but the tasks is received and triggered

- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 558
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
docs pending
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
stdlib type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
build type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
stdlib topic-email type-feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Ähnliche Issues
-
area/auth bug comp/agent P3 platform/discord type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
NousResearch/hermes-agent#117848 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
bancolombia/sentinel#23 ·
-
test md OffenCI
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100