from dattai2021 import worksheet
from dattai2021 import num
from dattai2021 import font_type
from dattai2021 import settingsheet

ziname = str(worksheet.acell('Y'+ str(num)).value)

###■セルの値にID記載###

id_value = "DA21"+str(1000+num)
worksheet.update_acell('A'+ str(num), id_value)

re_value = "発行メール送付済み"
worksheet.update_acell('C'+ str(num), re_value)



###################メール送信処理##########################
smtpserver= str(settingsheet.acell('B4').value)
sendermail= str(settingsheet.acell('B3').value)
smtpport= int(settingsheet.acell('B5').value)
smtppass= str(settingsheet.acell('B6').value)
sendm= str(settingsheet.acell('B2').value)

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication

smtp_obj = smtplib.SMTP(smtpserver,smtpport)
smtp_obj.starttls()
smtp_obj.login(sendermail, smtppass)

body = "JapanReturnの資料の書き込みが完了いたしました。"
msg = MIMEMultipart()
msg['Subject'] = "【JapanReturn】"+id_value+" - 資料の送付"
msg['To'] = sendm
msg['From'] = sendermail
msg.attach(MIMEText(body))

with open(r"./k02-1.pdf", "rb") as f:
    attachment = MIMEApplication(f.read())
attachment.add_header("Content-Disposition", "attachment", filename="k02-1.pdf")
msg.attach(attachment)
with open(r"./k02-2.pdf", "rb") as f:
    attachment = MIMEApplication(f.read())
attachment.add_header("Content-Disposition", "attachment", filename="k02-2.pdf")
msg.attach(attachment)
with open(r"./k01-1.pdf", "rb") as f:
    attachment = MIMEApplication(f.read())
attachment.add_header("Content-Disposition", "attachment", filename="k01-1.pdf")
msg.attach(attachment)
smtp_obj.send_message(msg)
smtp_obj.quit()


