Skip to content

Feature Request: Allow "sender" to be set per-message #229

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

Closed
kaperont opened this issue May 9, 2025 · 1 comment · Fixed by #230
Closed

Feature Request: Allow "sender" to be set per-message #229

kaperont opened this issue May 9, 2025 · 1 comment · Fixed by #230

Comments

@kaperont
Copy link
Contributor

kaperont commented May 9, 2025

Feature Request

Would like to specify the sender on a per-message basis.

Problem Statement

There is no convenient way to set the sender on a message, since it is always set from ConnectionConfig.MAIL_FROM.

Suggested Solution

MessageSchema should have an optional from and from_name attribute that defaults to the values set in the ConnectionConfig.

e.g.

# fastapi-mail/fastapi_mail/schemas.py

class MessageSchema(BaseModel):
    ...
    from: Optional[EmailStr] = None
    from_name: Optional[str] = None
    ...
# fastapi-mail/fastapi_mail/fastmail.py

class FaseMail(_MailMixin):
    ...
    async def __sender(self, message: MessageSchema) -> Union[EmailStr, str]:
        sender = message.from or self.config.MAIL_FROM
        if (from_name := message.from_name or self.config.MAIL_FROM_NAME) is not None:
            return formataddr((from_name, sender))
        return sender
    ...
@sabuhish
Copy link
Owner

Hey @kaperont, correct we dont have this feature per email. That is good approach, I have reviewd your PR, for me that looks great! Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants