Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import smptlib\n",
"from email.message import EmailMessage\n",
"\n",
"import getpass\n",
"password = getpass.getpass('Password : ')\n",
"\n",
"message = EmailMessage()\n",
"message['Subject'] = '이메일 제목'\n",
"message['From'] = 'hasblue@naver.com'\n",
"message['To'] = 'neverlish@gmail.com' # 수신자 이메일 다수 (구분자: 콤마)\n",
"\n",
"message.set_content('''이메일내용\n",
"\n",
"안녕하세요. AskDjango입니다.\n",
"\n",
"이 부분에는 이메일의 내용을 쓰실 수 있으며, HTML은 불가합니다.\n",
"HTML을 쓰시면 태그가 그대로 노출됩니다.\n",
"\n",
"여러분의 파이썬/장고 페이스메이커가 되겠습니다. 감사합니다;)''')\n",
"\n",
"with smptlib.SMTP_SSL('smtp.naver.com', 465) as server:\n",
" server.ehlo()\n",
" server.login('hasblue', password)\n",
" server.send_message(message)\n",
"\n",
"print('이메일을 발송했습니다.')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
117 changes: 117 additions & 0 deletions python/askdjango-work-automation/01 - 이메일 보내기.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 텍스트 메일 보내기"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Password : ········\n",
"이메일을 발송했습니다.\n"
]
}
],
"source": [
"import os\n",
"import smtplib\n",
"from email.message import EmailMessage\n",
"from email.mime.application import MIMEApplication\n",
"\n",
"import getpass\n",
"password = getpass.getpass('Password : ')\n",
"\n",
"message = EmailMessage()\n",
"message['Subject'] = '이메일 제목'\n",
"message['From'] = 'hasblue@naver.com'\n",
"message['To'] = 'neverlish@gmail.com' # 수신자 이메일 다수 (구분자: 콤마)\n",
"\n",
"message.set_content('''이메일내용\n",
"\n",
"안녕하세요. AskDjango입니다.\n",
"\n",
"이 부분에는 이메일의 내용을 쓰실 수 있으며, HTML은 불가합니다.\n",
"HTML을 쓰시면 태그가 그대로 노출됩니다.\n",
"\n",
"여러분의 파이썬/장고 페이스메이커가 되겠습니다. 감사합니다;)''')\n",
"\n",
"message.add_alternative('''\n",
" <h1>AskDjango VOD</h1>\n",
" \n",
" <img src=\"cid:f1.jpg\" />\n",
" \n",
" <p>이 부분에는 이메일의 내용을 쓰실 수 있으며, HTML은 불가합니다.\n",
"HTML을 쓰시면 태그가 그대로 노출됩니다.\n",
"\n",
"여러분의 파이썬/장고 페이스메이커가 되겠습니다. 감사합니다;)</p>\n",
"''', subtype='html')\n",
"\n",
"# 이미지 첨부\n",
"filepath_list = ['./f1.jpg', './f2.jpg', './f3.jpg']\n",
"for filepath in filepath_list:\n",
" with open(filepath, 'rb') as f:\n",
" filename = os.path.basename(filepath)\n",
" cid = filename\n",
" image_data = f.read()\n",
" part = MIMEApplication(image_data, name=filepath)\n",
" part.add_header('Content-ID', '<' + cid + '>')\n",
" message.attach(part)\n",
"\n",
"with smtplib.SMTP_SSL('smtp.naver.com', 465) as server:\n",
" server.ehlo()\n",
" server.login('hasblue', password)\n",
" server.send_message(message)\n",
"\n",
"print('이메일을 발송했습니다.')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
143 changes: 143 additions & 0 deletions python/askdjango-work-automation/02 - SMS 보내기 (카페24).ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SMS 잔여건수"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from base64 import b64encode\n",
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"url = \"http://sslsms.cafe24.com/sms_remain.php\"\n",
"user_id = b64encode(\"hadblue\".encode('euckr'))\n",
"secure = b64encode(\"9527f3f8c24a248eb3c992bae2db827b\".encode('euckr'))\n",
"mode = b64encode(\"1\".encode('euckr'))\n",
"\n",
"response = requests.post(url, data={\n",
" 'user_id': user_id,\n",
" 'secure': secure,\n",
" 'mode': mode,\n",
"})"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'300'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response.text"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"def send_sms(user_id, secure, sender, receivers, message):\n",
" params = {\n",
" 'user_id': user_id,\n",
" 'secure': secure,\n",
" 'mode': '1',\n",
" 'sphone1': sender[:3],\n",
" 'sphone2': sender[3:-4],\n",
" 'sphone3': sender[-4:],\n",
" 'rphone': ','.join(receivers),\n",
" 'msg': message,\n",
" }\n",
"\n",
" data = {}\n",
" for key, value in params.items():\n",
" if isinstance(value, str):\n",
" value = value.encode('euckr')\n",
" if key == 'msg':\n",
" value = value[:90].decode('euckr','ignore').encode('euckr')\n",
" data[key] = value\n",
"\n",
" response = requests.post('https://sslsms.cafe24.com/sms_sender.php', data=data)\n",
" return response.text"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'success,298'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"send_sms('hadblue', '9527f3f8c24a248eb3c992bae2db827b', '01087750467', ['01087750467'], '안녕하세요! SMS 보내기 테스트입니다.')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading