Email Script in Pyhton

Post Reply
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Email Script in Pyhton

Post by admin »

Basic Email

Code: Select all

import yagmail

user = yagmail.SMTP(user='ramajat@gmail.com',password='***********')
user.send(to ='accounts@ramajayam.in', subject ='Sample Subject',contents ='This is test mail for python automation', attachments = 'file.xlsx')
print("EMAIL SENT !!!")
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Re: Email Script in Pyhton

Post by admin »

Loop Based Email in Excel File

Code: Select all

import yagmail
import pandas as pd

# Load the Excel file
file_path = "List of Clients.xlsx"
df = pd.read_excel(file_path, sheet_name='Email', header=None)

df.columns = ["Email"]  # Rename the column properly
email_list = df["Email"].dropna().tolist()  # Extract email addresses

# Email credentials
user = yagmail.SMTP(user='rammbot@gmail.com', password='pvj*******l')

# Email details
subject = "Sample Subject"
contents = "This is a test mail for Python automation."
attachment = "file.xlsx"  # Update with the correct file name if needed

# Sending emails in a loop
for email in email_list:
    try:
        user.send(to=email, subject=subject, contents=contents, attachments=attachment)
        print(f"Email sent to: {email}")
        
    except Exception as e:
        print(f"Failed to send email to {email}: {e}")

print("EMAIL SENDING COMPLETED!")


    
Attachments
List of Clients.zip
(8.7 KiB) Downloaded 29 times
Balabaskumar
Posts: 3
Joined: Mon Mar 17, 2025 2:40 am
Location: Chennai
Region name: Southern

Re: Data Extracted from tally and Sent to Multiple Person Via Mail

Post by Balabaskumar »

Code: Select all

import pyodbc
import warnings
import pandas as pd
import time
from datetime import datetime
import pathlib

import subprocess
import os


warnings.filterwarnings('ignore')

pyodbc.drivers()
import pandas as pd
server = 'localhost,9000'
#database = 'database_name' # enter database name
cnxn = pyodbc.connect('DRIVER={Tally ODBC Driver64};SERVER='+server+';Trusted_Connection=yes;')
cursor = cnxn.cursor()
# select command
query = ''' 
Select $Name, $Parent, $Closingbalance from Ledger where $_PrimaryGroup = 'Sundry Debtors' And $Closingbalance > 100000'''
data = pd.read_sql(query, cnxn)
data.head()
data.to_csv('Sundry Debtor More than 1Lakh.csv')
print("Data Extracted")

Code: Select all

pyodbc.drivers()
import pandas as pd
server = 'localhost,9000'
#database = 'database_name' # enter database name
cnxn = pyodbc.connect('DRIVER={Tally ODBC Driver64};SERVER='+server+';Trusted_Connection=yes;')
cursor = cnxn.cursor()
# select command
query = ''' 
Select $Name, $Parent, $Closingbalance from Ledger where $_PrimaryGroup = 'Sundry Creditors' And $Closingbalance > 100000'''
data = pd.read_sql(query, cnxn)
data.head()
data.to_csv('Sundry Creditor More than 1Lakh.csv')
print("Data Extracted")

Code: Select all

pyodbc.drivers()
import pandas as pd
server = 'localhost,9000'
#database = 'database_name' # enter database name
cnxn = pyodbc.connect('DRIVER={Tally ODBC Driver64};SERVER='+server+';Trusted_Connection=yes;')
cursor = cnxn.cursor()
# select command
query = ''' SELECT $Key, $MasterId, $AlterID, $VoucherNumber, $Date, $VoucherTypeName, $Led_Lineno, $Type, $LedgerName, $Amount, $Led_Parent, $Led_Group, $Party_LedName, $Vch_GSTIN, $Led_GSTIN, $Party_GST_Type, $GST_Classification, $Narration, $EnteredBy, $LastEventinVoucher, $UpdatedDate, $UpdatedTime, $Nature_Led, $Led_MID, $CompanyName, $Year_from, $Year_to, $Company_number, $Path FROM A__DayBook'''
data = pd.read_sql(query, cnxn)
data.head()
data.to_csv('DayBook.csv')
print("Data Extracted")

Code: Select all

import yagmail
import pandas as pd

# Load the Excel file
file_path = "List of Clients.xlsx"
df = pd.read_excel(file_path, sheet_name='Email', header=None)

df.columns = ["Email"]  # Rename the column properly
email_list = df["Email"].dropna().tolist()  # Extract email addresses

# Email credentials
user = yagmail.SMTP(user='pheonix2985@gmail.com', password='ianh ckxb knri oovu')

# Email details
subject = "Hi Friends"
contents = "This is Bala Testing mail for Python automation."
attachment = ['DayBook.csv','Sundry Creditor More than 1Lakh.csv','Sundry Debtor More than 1Lakh.csv']  # Update with the correct file name if needed

# Sending emails in a loop
for email in email_list:
    try:
        user.send(to=email, subject=subject, contents=contents, attachments=attachment)
        print(f"Email sent to: {email}")
        
    except Exception as e:
        print(f"Failed to send email to {email}: {e}")

print("EMAIL SENDING COMPLETED!")


    
Attachments
Automated Mail.zip
(1.31 KiB) Downloaded 6 times
BalaTheGreat
Post Reply