|
from email.mime.multipart import MIMEMultipart |
|
from email.mime.text import MIMEText |
|
from email.mime.image import MIMEImage |
|
import smtplib |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fromadd = "[email protected]" |
|
password = "httscgatatbbxxur" |
|
|
|
|
|
def gmail_login(): |
|
try: |
|
server = smtplib.SMTP('smtp.gmail.com', 587) |
|
server.starttls() |
|
server.login(fromadd, password) |
|
return server |
|
except Exception as e: |
|
print("*** MAIL ERROR ***"*10) |
|
print(e) |
|
|
|
def send_user_email(hostname,text_output,Method): |
|
|
|
try: |
|
|
|
html_body="" |
|
html_body = f"""<html> |
|
<body> |
|
<p> |
|
{hostname}<br/> |
|
Method: {Method}<br/> |
|
Generated text: {text_output}<br/> |
|
</p> |
|
<br /> |
|
</body> |
|
</html>""" |
|
|
|
toadd = "[email protected]" |
|
subject = "OCR generated text" |
|
|
|
msg = MIMEMultipart("alternative") |
|
|
|
msg['From'] = fromadd |
|
msg['To'] = toadd |
|
msg['Subject'] = subject |
|
|
|
|
|
|
|
|
|
|
|
|
|
part2 = MIMEText(html_body, "html") |
|
msg.attach(part2) |
|
|
|
|
|
|
|
|
|
|
|
server = gmail_login() |
|
print("login success") |
|
temp = server.sendmail(fromadd, toadd, msg.as_string()) |
|
print("temp=.", temp) |
|
print("email sent to", toadd) |
|
|
|
print("** Mail Successfully Sent !***") |
|
return True |
|
except Exception as e: |
|
print("Error while sending feedback email => ", e) |
|
return False |