Spaces:
Running
Running
pragnakalp
commited on
Commit
•
0d71e3c
1
Parent(s):
618bbc5
changes in sending mail
Browse files- send_email_user.py +39 -25
send_email_user.py
CHANGED
@@ -1,34 +1,46 @@
|
|
1 |
-
import os
|
2 |
-
import sendgrid
|
3 |
-
from sendgrid import SendGridAPIClient
|
4 |
-
from sendgrid.helpers.mail import Mail
|
5 |
-
from email.mime.application import MIMEApplication
|
6 |
from email.mime.multipart import MIMEMultipart
|
7 |
from email.mime.text import MIMEText
|
8 |
from email.mime.image import MIMEImage
|
9 |
-
import smtplib
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def gmail_login():
|
16 |
try:
|
17 |
-
server = smtplib.
|
18 |
-
server.
|
19 |
-
server.login(
|
20 |
return server
|
21 |
except Exception as e:
|
22 |
print("*** MAIL ERROR ***"*10)
|
23 |
print(e)
|
24 |
|
25 |
-
def send_user_email(
|
26 |
|
27 |
try:
|
28 |
-
attachment = input_img
|
29 |
-
|
30 |
-
text =f"A user has submitted a image for OCR.\r\n\r\{hostname}\rMethod: {Method}\r\Result: {text_output}"
|
31 |
-
html = """<html><body><img src='flagged/img/0.jpg' border='0' /><br /></body></html>"""
|
32 |
html_body = f"""<html>
|
33 |
<body>
|
34 |
<p>
|
@@ -40,7 +52,7 @@ def send_user_email(input_img,hostname,text_output,Method):
|
|
40 |
</body>
|
41 |
</html>"""
|
42 |
|
43 |
-
toadd =
|
44 |
subject = "OCR generated text"
|
45 |
|
46 |
msg = MIMEMultipart("alternative")
|
@@ -48,19 +60,21 @@ def send_user_email(input_img,hostname,text_output,Method):
|
|
48 |
msg['From'] = fromadd
|
49 |
msg['To'] = toadd
|
50 |
msg['Subject'] = subject
|
|
|
51 |
# part1 = MIMEText(text, "plain")
|
52 |
# part2 = MIMEText(html_body, "html")
|
53 |
# msg.attach(part1)
|
54 |
-
part2 = MIMEText('<b>%s</b><br/><img src="cid:%s"/><br/>' % (html_body, attachment), 'html')
|
55 |
-
msg.attach(part2)
|
56 |
-
with open(attachment, 'rb') as fp:
|
57 |
-
img = MIMEImage(fp.read())
|
58 |
-
img.add_header('Content-ID', '<{}>'.format(attachment))
|
59 |
-
msg.attach(img)
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
server = gmail_login()
|
62 |
print("login success")
|
63 |
-
print(msg)
|
64 |
temp = server.sendmail(fromadd, toadd, msg.as_string())
|
65 |
print("temp=.", temp)
|
66 |
print("email sent to", toadd)
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from email.mime.multipart import MIMEMultipart
|
2 |
from email.mime.text import MIMEText
|
3 |
from email.mime.image import MIMEImage
|
4 |
+
import smtplib
|
5 |
|
6 |
+
# def send_user_email():
|
7 |
+
|
8 |
+
# sender="pragnakalp.dev33@gmail.com"
|
9 |
+
# password="httscgatatbbxxur"
|
10 |
+
# reciever="[email protected]"
|
11 |
+
|
12 |
+
# s = smtplib.SMTP('smtp.gmail.com', 587)
|
13 |
+
# s.starttls()
|
14 |
+
# s.login(sender,password)
|
15 |
+
|
16 |
+
|
17 |
+
# message = """Subject : Appointment Booking\n\n
|
18 |
+
# Hello,
|
19 |
+
# Your OCR generated successfully"""
|
20 |
+
# s.sendmail(sender, reciever, message)
|
21 |
+
# s.quit()
|
22 |
+
# mailsend=1
|
23 |
+
# return "Hellowwass"
|
24 |
+
|
25 |
+
fromadd = "[email protected]"
|
26 |
+
password = "httscgatatbbxxur"
|
27 |
+
# SENDGRID_API_KEY = "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"
|
28 |
|
29 |
def gmail_login():
|
30 |
try:
|
31 |
+
server = smtplib.SMTP('smtp.gmail.com', 587)
|
32 |
+
server.starttls()
|
33 |
+
server.login(fromadd, password)
|
34 |
return server
|
35 |
except Exception as e:
|
36 |
print("*** MAIL ERROR ***"*10)
|
37 |
print(e)
|
38 |
|
39 |
+
def send_user_email(hostname,text_output,Method):
|
40 |
|
41 |
try:
|
42 |
+
# attachment = input_img
|
43 |
+
html_body=""
|
|
|
|
|
44 |
html_body = f"""<html>
|
45 |
<body>
|
46 |
<p>
|
|
|
52 |
</body>
|
53 |
</html>"""
|
54 |
|
55 |
+
toadd = "pragnakalp.dev35@gmail.com"
|
56 |
subject = "OCR generated text"
|
57 |
|
58 |
msg = MIMEMultipart("alternative")
|
|
|
60 |
msg['From'] = fromadd
|
61 |
msg['To'] = toadd
|
62 |
msg['Subject'] = subject
|
63 |
+
|
64 |
# part1 = MIMEText(text, "plain")
|
65 |
# part2 = MIMEText(html_body, "html")
|
66 |
# msg.attach(part1)
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
# part2 = MIMEText('<b>%s</b><br/><img src="cid:%s"/><br/>' % (html_body, attachment), 'html')
|
69 |
+
part2 = MIMEText(html_body, "html")
|
70 |
+
msg.attach(part2)
|
71 |
+
# with open(attachment, 'rb') as fp:
|
72 |
+
# img = MIMEImage(fp.read())
|
73 |
+
# img.add_header('Content-ID', '<{}>'.format(attachment))
|
74 |
+
# msg.attach(img)
|
75 |
+
|
76 |
server = gmail_login()
|
77 |
print("login success")
|
|
|
78 |
temp = server.sendmail(fromadd, toadd, msg.as_string())
|
79 |
print("temp=.", temp)
|
80 |
print("email sent to", toadd)
|