From f2d2cb978ad7d929f9d4294b81c2954fe2100299 Mon Sep 17 00:00:00 2001
From: Manish Mahajan <113828751+Manu2603@users.noreply.github.com>
Date: Sun, 19 Feb 2023 15:18:13 +0530
Subject: [PATCH] send mail using python
With help of it you can be used to send mail to any mail address and also attach images in it.
---
Scripts/API/Mail_sending/mail.py | 51 ++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 Scripts/API/Mail_sending/mail.py
diff --git a/Scripts/API/Mail_sending/mail.py b/Scripts/API/Mail_sending/mail.py
new file mode 100644
index 000000000..87e3fc099
--- /dev/null
+++ b/Scripts/API/Mail_sending/mail.py
@@ -0,0 +1,51 @@
+def mail():
+ #import all required package
+ import smtplib
+ import random
+ from email.mime.multipart import MIMEMultipart
+ from email.mime.text import MIMEText
+ from email.mime.image import MIMEImage
+ otp=random.randint(1000,10000)
+
+#content of mail
+ content1 = '''
The verification code OTP - {}
\n*Note :
Do not share your one-time password (OTP)]\n
with anyone over phone or e-mail \n
as this could lead to fraud.'''.format(otp)
+ content2 = "*Please read: \n If you did not initiate the request, you do not \n need to take any further action and can \n safely disregard this email.\n\n"
+ content3 =" Thanks
HelpYourself
***No reply mail..
This is system generated mail do not reply to it."
+
+ sender= 'xyz@gmail.com'#replace with the mail of sender
+ passward = 'hzvwm'#replace with your sthird party permission passward of sender email
+ receiver = 'abc@gmail.com'#replace with receivers email
+
+ message = MIMEMultipart()
+ message['Subject'] = 'Please verify your email.'# replace with the subject of your mail
+ message.attach(MIMEText(content1, 'html'))
+
+ msgAlt = MIMEMultipart('alternative')
+ message.attach(msgAlt)
+
+ msgText = MIMEText('Something went wrong.\nImage cannot be displayed')
+ msgAlt.attach(msgText)
+
+ msgText = MIMEText('

', 'html')
+ msgAlt.attach(msgText)
+
+# place image in current directory
+ fp = open('logo baymax_.jpg', 'rb')# add image name you want to attach in mail
+ msgImage = MIMEImage(fp.read())
+ fp.close()
+
+ msgImage.add_header('Content-ID', '')
+ message.attach(msgImage)
+
+ message.attach(MIMEText(content2, 'plain'))
+ message.attach(MIMEText(content3, 'html'))
+ session = smtplib.SMTP('smtp.gmail.com', 587)
+ session.starttls()
+ session.login(sender, passward)
+ text = message.as_string()
+ session.sendmail(sender, receiver, text)
+ session.quit()
+ print('Mail Sent')
+
+
+mail()