Commit graph

161 commits

Author SHA1 Message Date
Aarol D'Souza
9eef4f6dae
fix: force type check in whitelisted methods (#37044)
* fix(contact): force type check in contact whitelisted methods

* fix(google_indexing): force type check in google_indexing whitelisted methods

* fix(assignment_rule): add type checks to assignment_rule whitelisted methods

* refactor: remove unused args

* fix(queue): add type hints to whitelisted methods in queue.py

* fix(auto_email_report): add type hints to whitelisted methods

* fix(dashboard): add type hints to whitelisted methods

* fix(sidebar_item_group): add type hints to whitelisted methods

* fix(weasyprint): add type hints to whitelisted methods

* fix(backups): add type hints to whitelisted methods

* fix(document_naming_settings): add type hints to whitelisted methods

* fix(get_latest_submissions): add type hints to whitelisted methods

* fix(custom_field): add type hints to whitelisted methods

* fix(customize_form): add type hints to whitelisted methods

* fix(personal_data_deletion_request): add type hints to whitelisted functions

* fix(__init__): add type hints to whitelisted methods

* fix(prepared_report): add type hints to whitelisted methods

* fix(session_default_settings): add type hints to whitelisted methods

* fix(document_follow): add type hints to whitelisted methods

* fix(route_history): add type hints to whitelisted methods

* fix(form_tour): add type hints to whitelisted methods

* fix(dashboard_settings): add type hints to whitelisted methods

* fix(address): add type hints to whitelisted methods

* fix(contact): add type hints to whitelisted methods

* fix(discussion_reply): add type hints to whitelisted methods

* fix(auto_repeat): add type hints to whitelisted methods

* fix: add the missing type hints and misc. corrections

* fix(email): add type hints to whitelisted methods

* fix(permitted_documents_for_users): add type hints to whitelisted methods

* fix: correct the type hints

* fix: int PK types

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
Co-authored-by: Ankush Menat <ankush@frappe.io>
2026-02-17 15:16:30 +00:00
Ankush Menat
c944981a3e
fix: Lock email queue before sending (#35334)
Avoids duplicate flushes.
2025-12-18 10:36:24 +00:00
sokumon
8e9187483c fix: avoid circular import 2025-07-15 18:03:41 +05:30
sokumon
6ff0c937d7 fix: use get_retry method and change error message 2025-07-15 17:44:53 +05:30
sokumon
74b4acacd4 fix: better name for the retry job 2025-07-14 18:30:37 +05:30
sokumon
2bbf72061c fix: dont let email queue stay in Sending status 2025-07-14 18:10:43 +05:30
Sagar Vora
b3e1eda4c8
feat: global frappe.in_test flag (#32960)
* feat: global `frappe.in_test` flag

* feat: helper utility to toggle `frappe.in_test`

* fix: use `toggle_test_mode` util

* fix: use `frappe.in_test`

* chore: add comment explaining global `in_test`

* chore: ignore commit replacing flag usage

* test: temporarily disable `frappe.in_test`

this worked earlier because flag was set in werkzeug.local which was separate for API test client

* test: add comment explaining change
2025-06-17 19:19:31 +05:30
Suhail
97a1d38814
fix: store unsubscribe params properly (#31583)
* fix: store unsubscribe params properly

Earlier we had a field `unsubscribe_param` but it wasn't used anywhere to store the params.
This made sure only email, doctype and docname was passed as the params while unsubscribing and no custom params wasn't.

* fix: convert unsubscribe_params dict to json before storing
2025-03-13 14:41:45 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Ankush Menat
a4382fda5a fix: Automatically close SMTP connections on exit 2023-11-04 11:51:42 +05:30
Ankush Menat
d5d0dfb58b perf: Reuse SMTP connection when flushing email queue
This depends on https://github.com/frappe/frappe/pull/23070
2023-11-04 11:32:48 +05:30
Ankush Menat
4e318a0280 fix: Abort flushing email queue if >50% fail.
When email queue batch failes >33% with >10 count, frappe will now abort
sending emails.

We already notify users via system notification so this
assumes that user will notice it and fix it in sometime.

With previous commits we also prioritize fresh emails over retries.
2023-11-04 11:25:09 +05:30
Ankush Menat
050c0b26f8 fix: flush emails from single background jobs 2023-11-04 11:23:44 +05:30
Ankush Menat
be2beeed9e
fix: improve email queue reliability (#23070)
* feat: control email queue batch size with config

* fix: Give emails who failed once less priority while sending
2023-11-03 15:10:37 +05:30
Sagar Vora
7aed89ae4d test: set request before verifying 2023-08-05 14:43:45 +05:30
Kevin Shenk
70da4ba51d
fix: typo on enqueue args
The deduplicate argument was missing the 'l'.
2023-07-01 13:56:50 -04:00
Ankush Menat
31d05b466a perf: Email queue dedup using job id instead of name 2023-06-29 18:05:09 +05:30
phot0n
1f8598891e fix: remove infinite sending retries for certain exceptions for email queue
* chore: remove expired status & set_expiry job from email queue
2023-06-09 14:38:55 +05:30
phot0n
4ceafe14e3 chore: remove unused is_background_task and add_to_sent_list -> update_recipient_status_to_sent
* set status to be hidden in queue doc
* don't maintain a list of sent to recipeint, a boolean is enough to set the status to partially sent
2023-06-08 16:19:37 +05:30
Sabu Siyad
2ec893278a
fix: email: get unsub email: use cstr instead of encode (#20985)
`encode` fails if reference name is an integer. use `cstr` instead which
use `as_unicode` under the hood
2023-05-14 17:29:38 +05:30
phot0n
a0d1d1bd0e test: fix test_unsubscribe 2023-02-01 21:37:23 +05:30
stephen
6b0950e1d2
fix: prevent emails from being queued multiple times (#19386)
* fix: prevent emails from being queued multiple times

* style: fmt

* refactor: optimistic error handling

- Combined email queue sending to single call instead of different
  branches for testing.
- If failing to get jobs -> attempt sending anyway. Failure could be
  form one bad job which shouldn't completely stop everything.

* chore: type

Co-authored-by: Ankush Menat <ankush@frappe.io>
2022-12-22 19:02:18 +05:30
Ankush Menat
b7a7f97a7a refactor: convert get email count query to ORM
- also fix capitalization of column names on postgres
2022-08-16 10:53:28 +05:30
Sagar Vora
4b0a9da400 refactor: rename hold_queue to suspend_email_queue 2022-07-18 22:32:12 +05:30
Sagar Vora
9a7f92ca1d fix!: allow system managers to toggle email queue 2022-07-18 16:53:49 +00:00
Ankush Menat
069b0ec650 chore: py38 safe typehint 2022-06-29 11:01:55 +05:30
Gavin D'souza
07d7b34fd9 refactor: get_unsubscribe_message
* Add fallback label "Unsubscribe" instead of printing None in the email
* Add typing hints, f-stringify & make code DRY-er for better readability
2022-06-28 12:08:00 +05:30
Ankush Menat
ea416f9d6b feat: log settings with "interface"
We have hardcoded "Log settings" to only apply on 3 doctypes, there are
few more logging doctypes in core which are not cleared right now, on
top of that it's not easy for user to configure all logging behaviour
from one place.

This change adds a table on log settings where logging doctypes that
support the interface required by log settings can auto-register and
show up in settings.

Currently only supported configuration is "number of days" to keep.
2022-06-15 12:30:38 +05:30
Ankush Menat
00f665c634 fix: email queue cleanup in pure SQL
Currently this background job constantly fails because of the way query
is written:

1. It tries to find all docs to delete using select query
2. Deletes them by using `in query` with a HUGE amount of docs
3. Deletes child table with parent, again using `IN` query with huge
   amount of docs.

This times out and never finishes on old sites.

Solution:

1. Modified deletion to straightaway delete all main table rows that are
   older
2. Apply same deletion logic to child table rows.

PS: This has potential to leave some orphan child table rows behind for few more days iff modified time was later than parent doc (this is quite rare). But it's safe since child table doesn't contain "links" anyway.
2022-05-25 09:42:12 +05:30
Rushabh Mehta
626ef14e1e fix(linting): fix quotes 2022-04-18 17:29:03 +05:30
Rushabh Mehta
57a55e4225 feat(minor): Add document reference to Error Log and doc.log_error 2022-04-18 17:29:03 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Faris Ansari
151a95aa30 fix: remove spaces from email placeholders
spaces get converted to %20 which breaks text replacement
2022-04-04 17:11:14 +05:30
Gavin D'souza
b79d55c5d3 refactor(minor): clear_outbox
* Use pluck API instead of building dict and then accesing keys
* Styled query
* Added type hints
2022-03-23 13:18:22 +05:30
shadrak gurupnor
75583bf692 fix: removed redundant pieces & rewrote the query with qb 2022-02-24 18:02:15 +05:30
shadrak gurupnor
c2c858f70e fix: clean up logs job was broken 2022-02-24 09:49:43 +05:30
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
2021-09-03 12:02:59 +05:30
Gavin D'souza
d63affc732 refactor(minor): Use ORM instead of raw delete queries
Modified query building for "IN" statements, as well as older condition
builders to use frappe.db.delete
2021-07-28 19:04:18 +05:30
Aradhya-Tripathi
a256219dd2 refactor: moved from raw queries in frappe email to
frappe orm
2021-07-21 19:16:59 +05:30
leela
97ac79a295 fix: consider email account while checking email limits
Added email_account argument for out going email count utility functions as
these are used to validate email limits.
2021-06-11 13:54:54 +05:30
Gavin D'souza
2ad9d202cb Merge branch 'develop' of github.com:frappe/frappe into drop-py2-code 2021-06-03 11:21:55 +05:30
leela
8e3b358b9f refactor: email queue builder is added
replaced queue.send function with Queue builder.
Queue builder builds a queue from sendmail request and sends the mail
if requested to send mail immediately.
2021-06-01 21:39:02 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30
leela
59bfc12da6 refactor: Cleaned Email Queue sendmail functionality
* Sending mail works independently
* You can send a mail by calling Queue_doc.send()
* Used context manager to track exceptions while sending mails
2021-05-06 10:08:50 +05:30
leela
a8f74d9471 refactor: Move finding email accounts code to EmailAccount doctype 2021-05-03 06:22:35 +05:30
Suraj Shetty
e6f551d610 feat: Add with_container argument and update email style 2021-01-21 11:17:08 +05:30
Saurabh
07e4885775 fix: renaming of fields and test fixes 2020-10-20 13:19:12 +05:30
Saurabh
b23e2cc311 fix: handle encoding exceptions while appending email to sent email folder 2020-08-06 19:09:35 +05:30
Suraj Shetty
a6c68f7dc0
fix: Initialize email_sent_to_any_recipient outsite try block (#10866)
to avoid UnboundLocalError: local variable
'email_sent_to_any_recipient' referenced before assignment
2020-06-30 17:38:27 +05:30
Abhishek Kedar
205c852f1c
fix: removed from_test parameter in send_one function
from_test parameter is not at all used anywhere in the send_one function so removed it, and its value will be always False.
2020-04-28 11:32:24 +05:30