def email_page(request): t = get_template('email.html') email = EmailMessage('Hello', 'Test<br>break', 'email@hotmail.com',['email@hotmail.com']) email.content_subtype = "html" workbook = xl.Workbook('ex.xlsx') worksheet = workbook.add_worksheet() worksheet.write(0, 0, 'Total') workbook.close() email.attach("ex.xlsx", workbook, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') email.send() return HttpResponse(t.render(Context({})), status=200)
I tried the following changes on the email.attach line:
workbook.read() - read is not an attribute of workbook workbook.getvalue()
workbook.getvalue() - getvalue is not an attribute of workbook
workbook - TypeError: 'File' object does not support indexing
score:2
def email_page(request):
t = get_template('email.html')
email = EmailMessage('Hello', 'Test<br>break', 'email@hotmail.com',['email@hotmail.com'])
email.content_subtype = "html"
f = StringIO.StringIO() # create a file-like object
workbook = xl.Workbook(f)
worksheet = workbook.add_worksheet()
worksheet.write(0, 0, 'Total')
workbook.close()
email.attach("b.xlsx", f.getvalue(), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
email.send()
return HttpResponse(t.render(Context({})), status=200)
This way we can still use xlsx writer to make the file.
Credit To: stackoverflow.com
Related Query
- Email xlsx attachment Django
- Sending a text + HTML email with a calendar ICS attachment in Django or Python
- How to send pdf as an email attachment in Django
- Sending email asynchronously with attachment in Django
- Sending email from a Django app hosted on Heroku with attachment stored in AWS S3
- Send email with attachment django
- Sending Images as inline Attachment within HTML Email template using Django
- Sending email with an attachment from Django with Amazon-SES, Celery Tasks
- Sending an email with django custom forms with an attachment and without the need of a database
- Django rest framework: sendgrid email with attachment without model only filefield to open file and send button to send email
- Sending Email attachment using django :
- Creating email templates with Django
- Django - Login with Email
- Testing email sending in Django
- Giving email account a name when sending emails with Django through Google Apps
- Accepting email address as username in Django
- How to send html email with django with dynamic content in it?
- Django allauth social login: automatically linking social site profiles using the registered email
- Django sending email
- Log in user using either email address or username in Django
- Django Custom User Email Account Verification
- Manually trigger Django email error report
- EmailBackend for sending email through multiple SMTP in Django
- Sending emails with attachment in django
- I continuously receive `Invalid HTTP_HOST header` error email after I upgrade my django site from http to https
- Attach generated CSV file to email and send with Django
- django allauth facebook redirects to signup when retrieved email matches an existing user's email?
- Using email as username field in Django 1.5 custom User model results in FieldError
- how to send asynchronous email using django
- Setting up email with Sendgrid in Heroku for a Django App
More Query from same tag
- How do you add environment variables to your django project
- Skip Django Allauth " You are about to sign in using a third party account from Google" page
- Django model not saving when calling save()
- Adding extra field in admin for custom user in Django 1.11
- RSS Parser for Django
- Differences between Django one-to-one and foreign key relationships at db level?
- Render current status only on template in StreamingHttpResponse in Django
- Django : custom management command not registered using app config
- Custom LoginView in Django 2
- See if a user has just logged in?
- How to save extra fields on registration using custom user model in DRF + django-rest-auth
- Django: update only items that are checked
- How to add multiple lines of the Formset?
- Constant data stream with Django channels
- is it possible to manually restart celery task