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
How to send email as Jinja template with image? #173
Comments
Celery worker file from celery import Celery
from app.core.config import settings
from app.email.email import send_birthday_reminder
celery = Celery(__name__)
celery.conf.broker_url = settings.CELERY_BROKER_URL
celery.conf.result_backend = settings.CELERY_RESULT_BACKEND
@celery.task(name="create_task")
def create_task():
send_birthday_reminder(
'customer@gmail.com', {"subject": "hi"}
) File for sending emails from asgiref.sync import async_to_sync
from fastapi_mail import ConnectionConfig, FastMail, MessageSchema
from app.core.config import BASE_DIR, settings
conf = ConnectionConfig(
MAIL_USERNAME=settings.MAIL_USERNAME,
MAIL_PASSWORD=settings.MAIL_PASSWORD,
MAIL_FROM=settings.MAIL_FROM,
MAIL_PORT=settings.MAIL_PORT,
MAIL_SERVER=settings.MAIL_SERVER,
MAIL_STARTTLS=False,
MAIL_SSL_TLS=False,
USE_CREDENTIALS=True,
TEMPLATE_FOLDER=BASE_DIR / 'templates'
)
@async_to_sync
async def send_birthday_reminder(email_to: str, content: dict):
message = MessageSchema(
subject='Birthday Reminder',
recipients=[email_to],
template_body=content,
subtype='html',
)
fm = FastMail(conf)
await fm.send_message(
message, template_name='email/birthday_reminder.html'
) |
Hi @morento101, I would suggest you use S3 or any other bucket that way it is much more useful I feel. |
@morento101 I am adding images to templates as described here: Customizing attachments by headers and MIME type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use FastAPI-Mail and Celery to send notifications in the background. I want to place the static image in the template and send it to the customer.
I discovered that a
url_for
function returns an absolute URL and can be used in img tag as src.The problem is that I get such an error, and I don't know how to solve it:
How can I solve this issue?
Is there a better way to send a template with an image?
The text was updated successfully, but these errors were encountered: