import win32com.client
import os
from PIL import ImageGrab, Image
def mailing(sender, receiver, reference, hidden_reference, dir_path):
outlook = win32com.client.Dispatch("Outlook.Application")
Txoutlook = outlook.CreateItem(0)
Txoutlook.Sender = sender
Txoutlook.To = receiver
Txoutlook.cc = reference
Txoutlook.BCC = hidden_reference
Txoutlook.Subject = "Daily Report 공유의 건"
file_list = os.listdir(dir_path)
files = [file for file in file_list]
excel_app = win32com.client.Dispatch('Excel.Application')
excel_app.Visible=False
workbook = excel_app.Workbooks.Open(os.path.join(dir_path, files[0]))
worksheet = workbook.Sheets[sheet_name1]
range_to_copy = worksheet.Range('A1:AH64')
range_to_copy.Copy()
clipboard_image = ImageGrab.grabclipboard()
img_file = r'이미지파일 경로\\img.png'
clipboard_image.save(img_file)
Txoutlook.BodyFormat = 2
attachment = Txoutlook.Attachments.Add(img_file)
cid = f"cid:{os.path.basename(img_file)}"
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", cid)
html_body = f"""
<html>
<body>
<p> Daily자료 공유드립니다.<br><br></p>
<img src="{cid}">
</body>
</html>
"""
Txoutlook.HTMLBody = html_body
attachment = os.path.join(dir_path, files[0])
Txoutlook.Attachments.Add(attachment)
Txoutlook.Send()