Skip to content

Commit e58e842

Browse files
authored
Merge pull request #4 from tai271828/pr-render-mail-config
Add suffix option
2 parents 8baf114 + 2e63c67 commit e58e842

24 files changed

+766
-48
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
name: New commit pushed
1+
name: New commit pushed or pull request created
22

3-
on:
4-
push:
3+
on: [push, pull_request]
54

65
jobs:
76
check:

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ verify_ssl = true
77
# task management
88
invoke = "*"
99
# test
10+
tox = "*"
1011
pytest = "*"
1112
pytest-cov = "*"
1213
pytest-mock = "*"

Pipfile.lock

Lines changed: 36 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ Options:
3535
}
3636
```
3737

38+
Please note the comma is able to be used as a receiver separator to send multiple people. For example, the following 3
39+
formats are all working:
40+
41+
A space following a comma
42+
```json
43+
{
44+
"common_data": {},
45+
"unique_data": [
46+
{"receiver_email": "somerec01@somedomain, somerec02@somedomain"}
47+
]
48+
}
49+
```
50+
51+
No space following a comma
52+
```json
53+
{
54+
"common_data": {},
55+
"unique_data": [
56+
{"receiver_email": "somerec01@somedomain,somerec02@somedomain"}
57+
]
58+
}
59+
```
60+
61+
Or mix both of the above two types
62+
```json
63+
{
64+
"common_data": {},
65+
"unique_data": [
66+
{"receiver_email": "somerec01@somedomain, somerec02@somedomain,somerec03@somedomain"}
67+
]
68+
}
69+
```
70+
71+
3872
* `--mails_path PATH`: The output path of the mails. The mail will be named as the receivers email address.
3973

4074
### Step 2: Send the generated mails
@@ -43,7 +77,7 @@ Options:
4377
python send_mail.py [OPTIONS] CONFIG_PATH
4478

4579
Options:
46-
--output_path PATH [default: mails_to_sent]
80+
--mails_path PATH [default: mails_to_sent]
4781
--attachment_file PATH
4882
```
4983

@@ -57,8 +91,28 @@ Options:
5791
}
5892
```
5993

94+
Please note the comma is used as a receiver separator to send multiple people.
95+
6096
* `--mails_path PATH`: The path of the mails to sent.
6197

98+
By issuing the `send_mail.py` command,
99+
you will be prompted to input the corresponding password of your smtp server.
100+
101+
```plaintext
102+
You are about to send the mails under "mails_to_sent". Do you want to continue? [y/N]: y
103+
Please enter your mail account: <sender email address in mail config>
104+
Please enter you mail password:
105+
INFO:root:Email sent to <receiver address in RECEIVER_DATA>!
106+
```
107+
108+
Currently we only support the smtp server of `gmail`,
109+
so you may want to use the one-time app password for security concern.
110+
To use gmail one-time app password, please go to
111+
`Manage your Goolge Account > Security > Signning to Google > App passwords` and then
112+
`Select app > Other`
113+
to generate your one-time app password. The generated password could be removed anytime
114+
if you are sure that you won't use it anymore.
115+
62116
## Contributing
63117
See [Contributing](contributing.md)
64118

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
{
22
"common_data": {
33
"sender_name": "Taihsiang Ho",
4-
"sender_team": "2020 台灣 Python 年會籌備團隊 贊助組"
4+
"sender_team": "2020 台灣 Python 年會籌備團隊 贊助組",
5+
"pycon_tw_20xx": "PyCon Taiwan 2020"
56
},
67
"unique_data": [
78
{
8-
"receiver_email": "sponsorship@pycon.tw",
9-
"receiver_name": "贊助組測試有限公司"
9+
"receiver_email": "tai271828+sponsorship.testemail.1@gmail.com",
10+
"receiver_name": "贊助組測試01有限公司"
11+
},
12+
{
13+
"receiver_email": "tai271828+sponsorship.testemail.2@gmail.com",
14+
"receiver_name": "贊助組測試02有限公司"
15+
},
16+
{
17+
"receiver_email": "tai271828+sponsorship.testemail.4@gmail.com, tai271828+sponsorship.testemail.4.1@pycon.tw, taihsiangho+sponsorship.testemail.4.2@gmail.com,tai271828+sponsorship.testemail.4.3@solvcon.net",
18+
"receiver_name": "贊助組測試04有限公司"
19+
},
20+
{
21+
"receiver_email": "tai271828+sponsorship.testemail.3@gmail.com",
22+
"receiver_name": "贊助組測試03有限公司"
1023
}
1124
]
1225
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Subject": "[測試][請忽略][PyConTW2020] 敬邀參與 PyCon Taiwan 2020 - 測試請忽略有限公司",
2+
"Subject": "[PyConTW2020] 敬邀參與 PyCon Taiwan 2020",
33
"From": "tai27182@pycon.tw",
44
"CC": "sponsorship@pycon.tw"
55
}

render_mail.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ def load_template(tmpl_path: Path) -> Template:
1515

1616

1717
def render_all_content(
18-
template: Template, common_data: Dict[str, str], unique_data: List[Dict[str, str]]
18+
template: Template,
19+
common_data: Dict[str, str],
20+
unique_data: List[Dict[str, str]],
21+
separator: str,
1922
) -> Dict[str, str]:
2023
recv_to_mail = dict()
2124
for data in unique_data:
2225
data.update(common_data)
23-
recv_to_mail[data["receiver_email"]] = template.render(**data)
26+
if separator:
27+
subject = separator.join([data["receiver_email"], data["receiver_name"]])
28+
else:
29+
subject = data["receiver_email"]
30+
recv_to_mail[subject] = template.render(**data)
2431
return recv_to_mail
2532

2633

@@ -33,24 +40,30 @@ def export_mails(recv_to_mail, output_path):
3340
@click.command()
3441
@click.argument("template_path", type=click.Path(exists=True))
3542
@click.argument("receiver_data", type=click.Path(exists=True))
43+
@click.option(
44+
"--separator",
45+
default="",
46+
show_default=True,
47+
help="Separator used for subject suffix",
48+
)
3649
@click.option(
3750
"--output_path",
3851
type=click.Path(exists=False),
3952
default="mails_to_sent",
4053
show_default=True,
4154
)
42-
def main(template_path, receiver_data, output_path):
55+
def main(template_path, receiver_data, separator, output_path):
4356
if not os.path.isdir(output_path):
4457
logging.info('Create directory "%s"', output_path)
45-
os.mkdir(output_path)
58+
Path(output_path).mkdir(parents=True)
4659

4760
with open(receiver_data, "r") as input_file:
4861
data = json.load(input_file)
4962
common_data = data["common_data"]
5063
unique_data = data["unique_data"]
5164

5265
template = load_template(template_path)
53-
recv_to_mail = render_all_content(template, common_data, unique_data)
66+
recv_to_mail = render_all_content(template, common_data, unique_data, separator)
5467
export_mails(recv_to_mail, output_path)
5568

5669

0 commit comments

Comments
 (0)