pallets-eco/flask-mail

smtplib.SMTPDataError: (451, b'Error: queue file write error')

chendongxtu opened this issue · 1 comments

i am sorry to bother you.
background:
i have some crontab task every morning. "make-weekly-auction-data" is just one of them.
other tasks can send email with excel attached-file success. but this task "make-weekly-auction-data" always failed recently.
i am sure some of this cron tasks attach file data is bigger than this task. but when all the data statisticed, when i wanna send email ,
error is comming as follwing:
[2022-11-28, 16:36:58 CST] {pod_manager.py:226} INFO - /report/report/init.py:27: FlaskWTFDeprecationWarning: "flask_wtf.CsrfProtect" has been renamed to "CSRFProtect" and will be removed in 1.0.
[2022-11-28, 16:36:58 CST] {pod_manager.py:226} INFO - csrf = CsrfProtect()
[2022-11-28, 16:36:58 CST] {pod_manager.py:226} INFO - /usr/local/lib/python3.7/site-packages/pymysql/cursors.py:170: Warning: (3170, "Memory capacity of 8388608 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query.")
[2022-11-28, 16:36:58 CST] {pod_manager.py:226} INFO - result = self._query(query)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - Traceback (most recent call last):
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "manage.py", line 39, in
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - manager.run()
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/site-packages/flask_script/init.py", line 417, in run
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - result = self.handle(argv[0], argv[1:])
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/site-packages/flask_script/init.py", line 386, in handle
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - res = handle(*args, **config)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/site-packages/flask_script/commands.py", line 216, in call
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - return self.run(*args, **kwargs)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/report/report/commands/airflow.py", line 388, in make_weekly_auction_data
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - result = make_weekly_auction_data(execution_dt_str)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/report/report/accessory/email_report/auction_data.py", line 69, in make_weekly_auction_data
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - _send_auction_data(export_dt, end_dt, auction_data, WEEKLY)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/report/report/accessory/email_report/auction_data.py", line 116, in _send_auction_data
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - attach_file_bytes=auction_data.getvalue(),
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/report/report/accessory/email_report/utils.py", line 112, in send_mail
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - mail.send(msg)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/site-packages/flask_mail.py", line 492, in send
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - message.send(connection)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/site-packages/flask_mail.py", line 427, in send
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - connection.send(self)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/site-packages/flask_mail.py", line 192, in send
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - message.rcpt_options)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - File "/usr/local/lib/python3.7/smtplib.py", line 893, in sendmail
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - raise SMTPDataError(code, resp)
[2022-11-28, 16:37:03 CST] {pod_manager.py:226} INFO - smtplib.SMTPDataError: (451, b'Error: queue file write error')
[2022-11-28, 16:37:08 CST] {kubernetes_pod.py:473} INFO - Deleting pod: make-weekly-auction-data-a1758e1cb6684e6eac68f1e8443d8f80
[2022-11-28, 16:37:08 CST] {taskinstance.py:1889} ERROR - Task failed with exception

here is my code:
def send_mail(
recipients, subject, body, attach_filename, attach_file_bytes, sender=None
):
from flask_mail import Message
from report import mail

if (
    not recipients
    or not isinstance(recipients, list)
    or not subject
    or not body
    or not attach_filename
    or not attach_file_bytes
    or not isinstance(attach_file_bytes, bytes)
):
    raise Exception("argument error")

if not sender:
    sender = ("data-report", current_app.config.get("MAIL_USERNAME"))
elif isinstance(sender, tuple):
    sender = "%s <%s>" % sender

msg = Message(
    subject=subject,
    sender=sender,
    recipients=recipients,
)

msg.body = body

msg.attach(
    attach_filename,
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    attach_file_bytes,
)

mail.send(msg)

i saw some people say the data "attach_file_bytes" was over limit, but when i read the flask email source code, there not has a default maxium value.

so can you help me or give me idea to solve this problem? thanks very much

Closing this as I imagine the author has either answered the question for themselves or moved on. In the future, questions should go in https://github.com/pallets-eco/flask-mail/discussions