Commit f63ae275 by mohammed.shibili

email completed

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (sendMail)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sendMail.iml" filepath="$PROJECT_DIR$/.idea/sendMail.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
from scripts.servieces.send_mail import mail_creation
print("program to send file with attachments")
# calling the mail creation file
mail_creation()
server_name = 'smtp.gmail.com'
port_number = '465'
import pandas as pd
# fetching body contents
def body_content():
data_set = pd.read_excel("scripts/utils/Task3.xlsx")
column_mean = {}
column_maximum = {}
column_minimum = {}
for cols in data_set.columns:
if cols == "Timestamp":
continue
else:
timestamp = data_set['Timestamp'][data_set[cols].idxmax()]
max_value = data_set[cols][data_set[cols].idxmax()]
min_value = data_set[cols][data_set[cols].idxmin()]
column_mean.update({cols: data_set[cols].mean()})
column_maximum.update({timestamp: max_value})
column_minimum.update({timestamp: min_value})
body_message = f"average values {column_mean} \nmaximum value {column_maximum} \nminimum value {column_minimum}"
return body_message
from email.message import EmailMessage
from scripts.core.handlers.content_for_body import body_content
# attaching exel file
def file_attach(from_address, to_address, subject):
from_address1 = from_address
to_address1 = to_address
subject1 = subject
body = body_content()
msg = EmailMessage()
msg['From'] = from_address1
msg['To'] = to_address1
msg['Subject'] = subject1
msg.set_content(body)
# opening file to be attached
with open("scripts/utils/Task3.xlsx", "rb") as file:
file_data = file.read()
file_name = file.name
msg.add_attachment(file_data, maintype='application', subtype='xlsx', filename=file_name)
return msg
import smtplib
from scripts.constants.server_details import server_name, port_number
# mail authentication
def mail_access(from_address, email_password, message):
try:
with smtplib.SMTP_SSL(server_name, port_number) as smtp:
smtp.login(from_address, email_password)
smtp.send_message(message)
except Exception as e:
print(e, "error while login")
print("login successful")
from scripts.core.handlers.fileattaching import file_attach
from scripts.core.handlers.mail_accessing import mail_access
# accepting details for sending mail
def mail_creation():
from_address = input("enter sender email ID")
email_password = input("enter sender password")
to_address = []
number_of_receivers = int(input("enter number of receivers"))
print("enter receivers mail IDs")
while number_of_receivers > 0:
to_address.append(input())
number_of_receivers = number_of_receivers - 1
subject = input("enter the subject")
message = file_attach(from_address, to_address, subject)
mail_access(from_address, email_password, message)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment