-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_app.py
executable file
·134 lines (122 loc) · 4.02 KB
/
email_app.py
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
133
134
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
You must already have an instance of the email_server running on the
remote machine, as well as the Proton-Bridge mail client
Created on Sun Feb 19 09:26:48 2023
@author: dale
"""
import sys
from pathlib import Path
from smtplib import SMTPDataError
MAIN_DIR = Path(__file__).parent
if str(MAIN_DIR) not in sys.path:
sys.path.append(str(MAIN_DIR))
if str(Path(MAIN_DIR, '__helpers__')) not in sys.path:
sys.path.append(str(Path(MAIN_DIR, '__helpers__')))
if __name__ == '__main__':
import time
import commands_for_remote_email as commands
from ssh_login import return_ssh_connection
app_dir = Path(__file__).parents[1]
html_path = None #f'{app_dir}/html_files/Cups and Bowls Newsletter 1.html'
from_email = None #'[email protected]'
url_str = None #'https://cupsnbowls.com/email_monitoring/email_test_1'
emails_path = None #f'{app_dir}/email_lists/test_list_1.csv'
png_path = None #f'{app_dir}/email_png/no_chalk_pdf_png_test.png'
pdf_path = None #f'{app_dir}/pdf_attach/cnb_newsletter_1.pdf'
if emails_path == None or html_path == None:
import argparse
parser = argparse.ArgumentParser(
description='Send email with html content'
)
parser.add_argument(
'html_path',
type=str,
help='HTML File Path'
)
parser.add_argument(
'emails_path',
type=str,
help='Path to CSV or Excel with "emails" column'
)
parser.add_argument(
'from_email',
type=str,
help='Email address sending emails from'
)
parser.add_argument(
'--url_str',
type=str,
default=None,
help='Final URL path for tracking'
)
parser.add_argument(
'--png_path',
type=str,
default=None,
help='Path to PNG for email body'
)
parser.add_argument(
'--pdf_path',
type=str,
default=None,
help='PDF File Path'
)
args = parser.parse_args()
emails_path = args.emails_path
html_path = args.html_path
from_email = args.from_email
url_str = args.url_str if args.url_str else None
png_path = args.png_path if args.png_path else None
pdf_path = args.pdf_path if args.pdf_path else None
conn = return_ssh_connection()
time.sleep(.5)
try:
commands.transfer_file_to_remote(
conn,
args.html_path,
'/home/opc/email_venv/html_files',
)
except:
commands.transfer_large_file_to_remote(
conn,
args.html_path,
'/home/opc/email_venv/html_files',
)
time.sleep(.5)
commands.transfer_file_to_remote(
conn,
args.emails_path,
'/home/opc/email_venv/email_lists',
)
time.sleep(.5)
if png_path:
commands.transfer_file_to_remote(
conn,
args.png_path,
'/home/opc/email_venv/email_png',
)
time.sleep(.5)
if pdf_path:
commands.transfer_file_to_remote(
conn,
args.pdf_path,
'/home/opc/email_venv/pdf_attach',
)
time.sleep(.5)
c1, c2, c3 = commands.create_send_email_commands(
args.html_path,
args.emails_path,
args.from_email,
url_str=args.url_str,
png_path=args.png_path,
pdf_path=args.pdf_path,
)
time.sleep(.5)
commands.run_remote_command_in_shell(conn, c1)
time.sleep(.5)
commands.run_remote_command_in_shell(conn, c2)
time.sleep(.5)
commands.run_remote_command_in_shell(conn, c3)
print('\nThe files have been successfully removed\n')