Currently, I am making a completely private mBaaS-like one, and if it becomes an OSS for everyone, I thought that I should think about accounts etc. so I sent an email.
Since PyAPNs only supports Python 2.x, I implemented it using Python 2 with the knowledge that it will be hit by some elementary school students. I think that it can be used as it is in Python 3.x, so if you feel like it, please
I'm still not compatible with Django 1.10. please forgive me
Virtual environment is ready with Virtualenv
$ pip install django==1.9.1
$ django-admin.py startproject sampleproject
$ django-admin.py startapp send_mail
For the time being, set settings.py
like this
sampleproject/settings.py
# coding: utf-8
・ ・ ・
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'send_mail', #add to
]
・ ・ ・
LANGUAGE_CODE = 'ja'
TIME_ZONE = 'Asia/Tokyo'
・ ・ ・
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'passowrd'
EMAIL_PORT = 587
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
sampleproject/urls.py
# coding: utf-8
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('send_mail.urls', namespace = 'send_mail')),
]
I want to route each application myself, so it looks like this.
send_mail/views.py
# coding: utf-8
from django.core.mail import EmailMessage
from django.http import HttpResponse
def index(request):
EmailMessage(u'subject', u'Text', to = ['[email protected]', '[email protected]']).send()
return HttpResponse('Send your register email')
Create ʻurls.pydirectly under
send_mail`
send_mail/urls.py
from django.conf.urls import url
from accounts import views
urlpatterns = [
url(r'^$', views.index, name = 'index'),
]
The source code itself looks like this. with this
$ python manage.py migrate
$ python manage.py runserver
And then http://127.0.0.1:8000
If it is true, you can do it by accessing, but it is a bit confusing due to Google's Authenticate specification.
In my case, I wanted to send an email for those who forgot their login password, so the content of the email looks like this.
An outrage that takes a screenshot of a Twitter tweet and pastes it as it is
Randomly create a string to reset the password
Python2.x series
import random, string
print(''.join([random.choice(string.letters + string.digits) for i in xrange(10)]))
Python3.x series
import random, string
print(''.join([random.choice(string.ascii_letters + string.digits) for i in range(10)]))
It's that easy!
Recommended Posts