Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MAIL_SEND_OPTIONS for send_mail #61

Merged
merged 4 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.0.1] - 2023-12-16

- Add configuration key `MAIL_SEND_OPTIONS` to support setting `mail_options` for `smtplib.SMTP.send_mail`
(e.g. `SMTPUTF8`) ([#61](https://github.com/waynerv/flask-mailman/pull/61)).

## [1.0.0] - 2023-11-04

- Drop Python 3.6 support.
Expand Down
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Flask-Mailman is configured through the standard Flask config API. A list of con

Default: False.

- **MAIL_SEND_OPTIONS**: `mail_options` for `smtplib.SMTP.sendmail`. If `SMTPUTF8` is included in `MAIL_SEND_OPTIONS`, and the server supports it, `from_mail` and `to` may contain non-ASCII characters.

Default: `[]`

Emails are managed through a *Mail* instance:
```python
from flask import Flask
Expand Down
3 changes: 3 additions & 0 deletions flask_mailman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def __init__(
use_localtime,
file_path,
default_charset,
mail_options,
backend,
):
self.server = server
Expand All @@ -218,6 +219,7 @@ def __init__(
self.use_localtime = use_localtime
self.file_path = file_path
self.default_charset = default_charset
self.mail_options = mail_options
self.backend = backend


Expand Down Expand Up @@ -255,6 +257,7 @@ def init_mail(config, testing=False):
config.get('MAIL_USE_LOCALTIME', False),
config.get('MAIL_FILE_PATH'),
config.get('MAIL_DEFAULT_CHARSET', 'utf-8'),
config.get('MAIL_SEND_OPTIONS', []),
mail_backend,
)

Expand Down
7 changes: 6 additions & 1 deletion flask_mailman/backends/smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ def _send(self, email_message):
recipients = [sanitize_address(addr, encoding) for addr in email_message.recipients()]
message = email_message.message()
try:
self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
self.connection.sendmail(
from_email,
recipients,
message.as_bytes(linesep='\r\n'),
mail_options=self.mailman.mail_options,
)
except smtplib.SMTPException:
if not self.fail_silently:
raise
Expand Down