Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- from email.mime.text import MIMEText
- import csv
- # SMTP Configuration
- SMTP_SERVER = 'mail.iitp.ac.in' # Replace with your SMTP server
- SMTP_PORT = 587 # Common SMTP port for TLS
- EMAIL_ADDRESS = 'email' # Your email address
- EMAIL_PASSWORD = 'avcd' # Your email password
- def send_email(to_email, subject, body):
- try:
- # Create the email message
- msg = MIMEText(body)
- msg['Subject'] = subject
- msg['From'] = EMAIL_ADDRESS
- msg['To'] = to_email
- # Connect to the SMTP server and send the email
- with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
- server.starttls() # Secure the connection
- server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
- server.sendmail(EMAIL_ADDRESS, to_email, msg.as_string())
- print(f"Email sent to {to_email}")
- except Exception as e:
- print(f"Failed to send email to {to_email}: {e}")
- def main():
- # Read the CSV file
- csv_file = 'Book1.csv' # Replace with the actual CSV file path
- with open(csv_file, newline='') as file:
- reader = csv.DictReader(file)
- for row in reader:
- # Prepare email content
- name = row['Name Roll'].split(' ', 1)[1] # Extract full name
- midsem = row['MidSem'].strip()
- endsem = row['EndSem'].strip()
- to_email = row['email'].strip()
- subject = "CN Marks MidSem Endsem"
- body = f"""
- Dear {name},
- Your CN marks are:
- MidSem (Out of 150): {midsem}
- EndSem (Out of 150): {endsem}
- Students whose marks got updated today are not reflected in this email. However, for final grading, the updated marks will be considered.
- Best regards,
- Mayank Agarwal
- """
- # Send the email
- send_email(to_email, subject, body)
- if __name__ == "__main__":
- main()
- csv sample
- #Name Roll,MidSem,EndSem,roll,email
- #2201AI01 ADIL CHADACHEEMADE,66,66,2201AI01,2201ai01_adil@iitp.ac.in
- #2201AI02 AKASH SINHA,88,127,2201AI02,2201ai02_akash@iitp.ac.in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement