Example #1
0
    def __init__(self,settings: ConnectionConfig ):

        if not issubclass(settings.__class__,Settings):
            raise  PydanticClassRequired('''Email configuruation should be provided from ConnectionConfig class, check example below:
         \nfrom fastmail import ConnectionConfig  \nconf = Connection(\nMAIL_USERNAME = "******",\nMAIL_PASSWORD = "******",\nMAIL_FROM = "your_from_email",\nMAIL_PORT = 587,\nMAIL_SERVER = "email_service",\nMAIL_TLS = True,\nMAIL_SSL = False)
         ''')

        self.settings = settings.dict()
Example #2
0
    async def send_message(self, message: MessageSchema, template_name=None):

        if not issubclass(message.__class__, BaseModel):
            raise PydanticClassRequired('''Message schema should be provided from MessageSchema class, check example below:
         \nfrom fastmail import MessageSchema  \nmessage = MessageSchema(\nsubject = "subject",\nrecipients= ["list_of_recipients"],\nbody = "Hello World",\ncc = ["list_of_recipients"],\nbcc =["list_of_recipients"],\nsubtype="plain")
         ''')

        if self.config.TEMPLATE_FOLDER and template_name:
            template = await self.get_mail_template(self.config.TEMPLATE_FOLDER, template_name)
            msg = await self.__preape_message(message, template)
        else:
            msg = await self.__preape_message(message)

        async with Connection(self.config) as session:
            await session.session.send_message(msg)