using multiple cc in this code wont send any email # -*- coding: utf-8 -*-
"""
Created on Fri Sep 20 22:34:23 2024

@author: vishv
"""

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.utils import formatdate, make_msgid
from datetime import datetime
import pytz
import pandas as pd
import time

csv_file_path = r"C:\emails\alias_final.csv"
df = pd.read_csv(csv_file_path)

tz_Mumbai = pytz.timezone('Asia/Kolkata')
datetime_Mumbai = datetime.now(tz_Mumbai).strftime('%d-%m-%Y %H:%M:%S.%f')

# Email credentials
username = 'iti_activist@fastmail.com'
password = '9q6y764h8f5d5m6m'

# List of recipients
#recipients = ['secled@gujarat.gov.in','director-det@gujarat.gov.in','pa2-det@gujarat.gov.in','dydir-det-gnr@gujarat.gov.in','admo-det@gujarat.gov.in']
#cc_recipients = ['pmh7rcr@gov.in','pkmishra.pmo@gov.in','osd2cm@gujarat.gov.in','min-led@gujarat.gov.in','chiefsecretary@gujarat.gov.in','secled@gujarat.gov.in','iti_email_registrar.unwind007@aleeas.com']

recipients = ['test-gokak2unb@srv1.mail-tester.com','iti_activist@fastmail.com']
cc_recipients = ['iti_email_registrar.unwind007@aleeas.com','tadin81302@marchub.com']

# Generate current date time
current_date_time = formatdate(localtime=True)

# Create SMTP session outside the loop
server = smtplib.SMTP('smtp.fastmail.com', 587)
server.starttls()  # Enable TLS
server.login(username, password)  # Login

#for email_sender in aliases:
for index, row in df.iterrows():
    #print(index)
    
    if pd.notnull(row['alias_domain']) and pd.notnull(row['alias_code']) and row['clean_username']=='Active' and row['alias_deleted'] == False:
        
        email_username = row['email_username']
        alias_domain = row['alias_domain']
        alias_email = email_username + '@' + alias_domain
        name = row['name']
                
        subject = 'Urgent: Policy Suggestions for Transfer Camp and Critical Seniority Concerns of Supervisor Instructors (Class-3) Transferred in Public Interest at ITIs in Gujarat'
        
        body = f'''
Reference: Circular issued by the Director, Office of the Director of Labour and Employment, Gandhinagar DET/0319/06/24 Dt. 25/06/2024

Respected Sir / Madam,

In reference to the above subject and circular, we would like to present the following suggestions and raise critical concerns regarding the seniority of Supervisor Instructors (Class-3) transferred in public interest.

1) Seniority points must be calculated based on either:
     a) Department Joining Date, or
     b) Last Self-Request Transfer Institute Joining Date, or
     c) Combined Seniority Points of Department Joining Date + Current Institute Joining Date, or
     d) Combined Seniority Points of Last Self-Request Transfer Institute Joining Date + Current Institute Joining Date.

     Reasons:
          i) According to the final merit list published via the referenced circular, detailed analysis reveals that 1237 employees (52% of total applicants) are ranked behind their much junior counterparts. Here is the detailed statistics:

          761 employees transferred in public interest (general cases) are outranked by 1094 junior employees, placing a total of 1479 juniors ahead of them in the merit list.

          211 employees who have never benefited from self-requested transfers (general cases) are outranked by over 160 junior employees, with potential out-ranking rising to 342 when assessed case-by-case.

          128 employees with one or more self-requested transfers are outranked by over 160 juniors, with a possible increase to 342 upon further review.

          108 employees transferred in public interest (spouse cases) are outranked by over 160 juniors. A total of 175 juniors are ahead, with potential out-ranking rising to 205 upon detailed assessment.

          19 employees transferred in public interest due to serious illness are outranked by 9 juniors, with 18 juniors ahead. This number could rise to 205 after further review.

          10 employees with disabilities transferred in public interest are outranked by 7 juniors, with 12 juniors ahead. Further review may push this number to 205.
          (More in depth analysis is available here, replace [dot] with .
          tinyurl[dot]com/ITI-seniority-analysis)

          ii) In most departments, there is either a public interest transfer policy or a self-request camp-based transfer policy, but not both. For example, like departments of Teachers and Talati have self-request transfer camp policies and no public interest transfers, while like departments of Police and RTO have public interest transfers without self-request transfer camps. 
However, even by combining public interest and self-request transfer policies, ITI employees transferred in public interest were unjustly ranked lower than their much juniors. This practice is morally unethical, violates the principles of natural justice, and contradicts the values outlined in GAD circulars.

2) Abolish Public Interest Transfers for Class-3 employees (teachers/instructors) in ITIs. These transfers are unjust, contradict GAD values, and burden the exchequer. They demotivate employees, harming teaching quality, reducing admissions, placements/apprenticeships and increasing dropouts. Additionally, they foster corruption by allowing arbitrary transfers, often used to punish whistleblowers, with employees being sent far from their hometowns as retaliation for speaking out.

3) Employees who wish to work in their hometown, should be awarded points based on the distance between their current institute and their hometown (Hometown as stated in their service book).

4) Allow All Employees to Participate in the Transfer Camp. According to the referenced and previous circulars, employees who took self-request transfers are arbitrarily excluded from participating in the camp. Past circulars indicated a 2-year ineligibility period, which has now increased to 3 years in the current circular. However, no such limitation was stated in their self-transfer orders and circulars. This policy unfairly benefits their junior colleagues.

5) Vacant Seats Must be as Sanctioned Mahekam. Also, certain courses, such as CNC, VMC Operator, Solar Technician, 3D Printing and many more lack sanctioned Mahekam, leaving these posts unfilled. This situation places unnecessary burdens on employees and severely impacts training quality. When determining available seats, the vacancy for Supervisor Instructors should include both the sanctioned Mahekam and the aforementioned courses.

These proposed suggestions are essential for creating a transparent and fair transfer camp. Implementing them will foster positivity among employees, enabling them to improve their teaching performance, which in turn will boost admissions and placements.

I trust that these recommendations will be considered seriously, leading to a transfer policy that ensures justice for employees transferred in public interest, allowing them to be placed above their junior colleagues.

Sincerely,
{name}
        '''
        # Create message container - the correct MIME type is multipart/mixed.
        msg = MIMEMultipart()
        msg['From'] = alias_email
        msg['Subject'] = subject
        msg['Date'] = current_date_time  # Add Date header
    
        # Optional headers
        msg['Reply-To'] = alias_email
        msg['X-Priority'] = '1'  # 1 indicates high priority
        msg['Disposition-Notification-To'] = alias_email
        msg['Return-Receipt-To'] = alias_email
    
        # Add unique message ID
        msg['Message-ID'] = make_msgid()
        
        # Attach body to the email
        msg.attach(MIMEText(body, 'plain'))

        msg['To'] = ', '.join(recipients)  # Join multiple recipients with commas
        msg['Cc'] = ', '.join(cc_recipients)  # Join multiple CC recipients with commas

        all_recipients = recipients + cc_recipients
            
        # Send the message via the server
        server.sendmail(alias_email, all_recipients, msg.as_string())  # Pass all recipients
        print(f"Email sent successfully from {alias_email}!")
        #time.sleep(10)
# Logout after sending all emails
server.quit()