{"action":"created","issue":{"url":"https://api.github.com/repos/sunscrapers/djoser/issues/91","labels_url":"https://api.github.com/repos/sunscrapers/djoser/issues/91/labels{/name}","comments_url":"https://api.github.com/repos/sunscrapers/djoser/issues/91/comments","events_url":"https://api.github.com/repos/sunscrapers/djoser/issues/91/events","html_url":"https://github.com/sunscrapers/djoser/issues/91","id":114722077,"number":91,"title":"possible E-mail improvement","user":{"login":"apokinsocha","id":11322329,"avatar_url":"https://avatars.githubusercontent.com/u/11322329?v=3","gravatar_id":"","url":"https://api.github.com/users/apokinsocha","html_url":"https://github.com/apokinsocha","followers_url":"https://api.github.com/users/apokinsocha/followers","following_url":"https://api.github.com/users/apokinsocha/following{/other_user}","gists_url":"https://api.github.com/users/apokinsocha/gists{/gist_id}","starred_url":"https://api.github.com/users/apokinsocha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apokinsocha/subscriptions","organizations_url":"https://api.github.com/users/apokinsocha/orgs","repos_url":"https://api.github.com/users/apokinsocha/repos","events_url":"https://api.github.com/users/apokinsocha/events{/privacy}","received_events_url":"https://api.github.com/users/apokinsocha/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-03T01:17:21Z","updated_at":"2015-11-08T00:08:12Z","closed_at":null,"body":"I want to quickly say first Djoser is a great package to kickoff DRF REST API projects and I've used it to its absolute maximal intent and beyond. Great job!\r\n\r\nI figure I would add my 2cents on some improvements though. Well, actually it's just one, the rest I found very flexible and inline with OOP/DRY.\r\n\r\nWith respect to sending e-mails, I would look into decoupling it from the DRF Views completely.\r\nSay for example you have attachments (which is not so uncommon), with Djoser as is, I had to make some minor but ugly modifications to Djoser and email views I sub-classed.\r\n\r\nCurrently Djoser does something similar with Email as TemplateView (or more generally, class based views) in Django, in that there is a \"get_context_data\" method etc...that is passed in to render the text (the e-mail subject, body etc...) given the path to the template (subject.html, body.html etc...).\r\n\r\nThis isn't bad, in most cases, but again, if I have to deal with attachments, and also with different types of scenarios (send to multiple recipients, bccs etc...), this may not be the best solution.\r\n\r\nInstead of coupling that to the DRF Views, I would decouple it completely and anytime Email functionality is needed, simply reference an Email class within the code and call it.\r\n\r\nHere is simple email class I wrote (I called it mixin class by accident) I'm using currently in one of my projects with djoser:\r\n\r\nhttps://github.com/apokinsocha/django-email-mixin/blob/master/django-email-mixin.py\r\n\r\nIt maybe a bit redundant with respect to djangos existing email function, but I wanted to encapsulate some additional common functionality with respect to e-mails.\r\n\r\nUsage example:\r\n```python\r\n    _file = some_file\r\n    html_body = DjangoEmailWrapper.get_template_text('email_body.txt', context=context)\r\n    subject = DjangoEmailWrapper.get_template_text('subject.txt', context=context, inline=True)\r\n    emails = ['test@gmail.com', 'test2@gmail.com']\r\n    msg = DjangoEmailWrapper(subject, getattr(settings, 'DEFAULT_FROM_EMAIL', None), html_body, bcc=emails, html_body=html_body)\r\n    msg.attach_file(_file)\r\n    msg.send_email()\r\n```\r\nI can do a PR in the near future to integrate it, if there is foreseeable use beyond my own.\r\nA pretty simple change in my view, but I think it cleans things up a bit and also allows to easily call DjangoEmailWrapper in other non-djoser views."},"comment":{"url":"https://api.github.com/repos/sunscrapers/djoser/issues/comments/154766629","html_url":"https://github.com/sunscrapers/djoser/issues/91#issuecomment-154766629","issue_url":"https://api.github.com/repos/sunscrapers/djoser/issues/91","id":154766629,"user":{"login":"konradhalas","id":101077,"avatar_url":"https://avatars.githubusercontent.com/u/101077?v=3","gravatar_id":"","url":"https://api.github.com/users/konradhalas","html_url":"https://github.com/konradhalas","followers_url":"https://api.github.com/users/konradhalas/followers","following_url":"https://api.github.com/users/konradhalas/following{/other_user}","gists_url":"https://api.github.com/users/konradhalas/gists{/gist_id}","starred_url":"https://api.github.com/users/konradhalas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/konradhalas/subscriptions","organizations_url":"https://api.github.com/users/konradhalas/orgs","repos_url":"https://api.github.com/users/konradhalas/repos","events_url":"https://api.github.com/users/konradhalas/events{/privacy}","received_events_url":"https://api.github.com/users/konradhalas/received_events","type":"User","site_admin":false},"created_at":"2015-11-08T00:08:12Z","updated_at":"2015-11-08T00:08:12Z","body":"Hi @apokinsocha! First of all thank you alot for your kind words about Djoser and your feedback.\r\n\r\nI agree that email functionality should be decoupled somehow from our views, and maybe `SendEmailViewMixin` is not the best idea. Do you have any suggestions how we should connect those two operations (user registration and sending email)? As you said, we shouldn't support only sending emails, but we should provide something more general. Maybe we can use Django signals or implement simple hooks system - definitely this should be something easy to extend for users.\r\n\r\nPlease give me a few more days, I have to think about it."}}