forked from sabuhish/fastapi-mail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
133 lines (85 loc) · 3.1 KB
/
install.sh
File metadata and controls
133 lines (85 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Installing dependencies for fastapi-mail, thanks for contirbuting if you have any issues feel free to open.
# Issue URL https://github.com/sabuhish/fastapi-mail/issues
set -e
CURRENT_DIRECTORY=$(pwd)
CURRENT_USER=$(whoami)
VERSION="0.3.0.4"
README_URL="https://github.com/sabuhish/fastapi-mail"
echo -e "Staring to create environment and installing dependencies for fastapi-mail"
function install(){
sudo -u $CURRENT_USER bash << EOF
echo -e "\ncreating virtualenv ..."
python3 -m venv .venv
source .venv/bin/activate
python --version
pip install --upgrade pip
echo "installing dependencies"
pip install "fastapi>=0.61.2" 'uvicorn>=0.12.2' 'jinja2>=2.11.2' "aiosmtplib>=1.1.4" "python-multipart>=0.0.5" "pydantic>=1.7.1" "email-validator>=1.1.1"
touch $CURRENT_DIRECTORY/main.py
echo "
from fastapi_mail import FastMail, ConnectionConfig, MessageSchema
import asyncio
conf = ConnectionConfig(
MAIL_USERNAME = 'YourUsername',
MAIL_PASSWORD = 'strong_password',
MAIL_FROM = 'your@email.com',
MAIL_PORT = '587',
MAIL_SERVER = 'your mail server',
MAIL_TLS = True,
MAIL_SSL = False
)
html = '<p>Hi this test mail, thanks for using Fastapi-mail</p>'
message = MessageSchema(
subject='Fastapi-Mail module',
recipients=['recipients'], # List of recipients, as many as you can pass
body=html,
subtype='html'
)
fm = FastMail(conf)
loop = asyncio.get_event_loop()
task = loop.create_task(fm.send_message(message,template_name="email_template.html"))
loop.run_until_complete(task)
loop.close()" >> main.py
echo "
from fastapi import FastAPI, BackgroundTasks
from starlette.responses import JSONResponse
from fastapi_mail import FastMail, MessageSchema,ConnectionConfig
from pydantic import EmailStr
from pydantic import EmailStr, BaseModel
from typing import List
class EmailSchema(BaseModel):
email: List[EmailStr]
conf = ConnectionConfig(
MAIL_USERNAME = 'YourUsername',
MAIL_PASSWORD = 'strong_password',
MAIL_FROM = 'your@email.com',
MAIL_PORT = '587',
MAIL_SERVER = 'your mail server',
MAIL_TLS = True,
MAIL_SSL = False
)
app = FastAPI()
html = '<p>Hi this test mail, thanks for using Fastapi-mail</p>'
@app.post('/email')
async def simple_send(email: EmailSchema) -> JSONResponse:
message = MessageSchema(
subject='Fastapi-Mail module',
recipients=email.dict().get('email'), # List of recipients, as many as you can pass
body=html,
subtype="html"
)
fm = FastMail(conf)
await fm.send_message(message)
return JSONResponse(status_code=200, content={'message': 'email has been sent'})" >> app.py
echo ""
echo -e "fastapi-mail: $VERSION"
echo -e "\nYou are ready to work on it, do the last things:"
echo -e "source .venv/bin/activate"
echo -e "cat main.py"
echo -e "\nPlease see the README file for more information:"
echo -e "$README_URL\n\n"
exit 0
EOF
}
install