I am working on an assignment in which I have to the send an email to the customer and if he clicks the accept link in the email, call the python function that completes the desired functionality and adds it to the database.
My question is how can we call a function from the email text.
The email might be like this:- Kindly click the accept link to complete the action ACCEPT
Demo email code:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def success_email():
sender = 'abhishek_talwar@xyz.com'
recipients = 'GANA_PANGO@xyz.com'
CC = 'abhishek_talwar@xyz.com'
subject = "Load Balance Request Completed"
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = recipients
msg['CC'] = CC
# Create the body of the message (a plain-text and an HTML version).
text = 'Hi this is a test mail'
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text.encode('utf-8'), 'html')
# Attach parts into message container.
msg.attach(part1)
s = smtplib.SMTP('mail1.xyz.com')
x =s.sendmail(sender, recipients, msg.as_string())
print x
action = 'Success email sent for'
print action
success_email()