smtp icloud working config
This commit is contained in:
139
smtp_send_working.ipynb
Normal file
139
smtp_send_working.ipynb
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "43f466e6-b25d-40ac-a36e-982650e3e8ed",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import email.message\n",
|
||||||
|
"import smtplib\n",
|
||||||
|
"import os\n",
|
||||||
|
"from dotenv import load_dotenv"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "45ec6b06-b667-46c2-9430-89f45b490c13",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"True"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 2,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# need to recall when edited\n",
|
||||||
|
"load_dotenv()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 3,
|
||||||
|
"id": "289d0ee8-21ca-4ab8-8514-2f6a248cd19f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"email to: cheeloychang@gmail.com\n",
|
||||||
|
"email from: spareclass@spareclass.com\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"smtp_server = os.getenv(\"SMTP_SRV\")\n",
|
||||||
|
"smtp_port = os.getenv(\"SMTP_PORT\")\n",
|
||||||
|
"smtp_user = os.getenv(\"SMTP_USER\")\n",
|
||||||
|
"smtp_pass = os.getenv(\"SMTP_PASS\")\n",
|
||||||
|
"email_to = os.getenv(\"EMAIL_TO\")\n",
|
||||||
|
"email_from = os.getenv(\"EMAIL_FROM\")\n",
|
||||||
|
"\n",
|
||||||
|
"print(f\"email to: {email_to}\")\n",
|
||||||
|
"print(f\"email from: {email_from}\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "7e57d507-242f-4c9b-9acc-557dd9429966",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"(235, b'2.7.0 Authentication successful')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"server = smtplib.SMTP(smtp_server, smtp_port)\n",
|
||||||
|
"server.starttls()\n",
|
||||||
|
"server.login(smtp_user, smtp_pass)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"id": "97b89233-abb9-4d51-aa3e-5d32c3be34ab",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"message = email.message.EmailMessage()\n",
|
||||||
|
"message.set_content('Hello, world!')\n",
|
||||||
|
"message['Subject'] = 'new registration'\n",
|
||||||
|
"message['From'] = email_from\n",
|
||||||
|
"message['To'] = email_to\n",
|
||||||
|
"\n",
|
||||||
|
"try:\n",
|
||||||
|
" errs = server.send_message(message)\n",
|
||||||
|
" if errs:\n",
|
||||||
|
" raise smtplib.SMTPException(f'Failures: {errs}')\n",
|
||||||
|
"finally:\n",
|
||||||
|
" server.quit()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "7ff412d6-d92f-457f-978c-ff2603a13a51",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"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.12.11"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
Reference in New Issue
Block a user