import yagmail import gradio as gr import os def execute(file_txt, user_mail, google_api_key, subject_text, content): import time mail_list = str(file_txt.decode("utf-8")).split("\n") if mail_list[-1] == "": mail_list = mail_list[:-1] yag = yagmail.SMTP(user_mail, os.getenv("GOOGLE_API_KEY", google_api_key)) print(mail_list) for mail in mail_list: yag.send(mail, subject_text, content) time.sleep(0.2) print("Mail gönderildi") return True with gr.Blocks() as demo: gr.Markdown('Auto mailing') with gr.Row(): file_input = gr.File(label='Mail listesini yükle', type='binary') with gr.Row(): user_mail = gr.Text(label='Gönderen Mail adresi', value=None) google_api_key = gr.Text(label="Google mail API anahtarı", value=None) with gr.Row(): subject_text = gr.Text(label='Mail konusu', value="") with gr.Row(): content = gr.Textbox(label='Gönderilecek mail metni', value="", lines=3) with gr.Row(): create_button = gr.Button('Gönder') response = create_button.click( execute, inputs=[file_input, user_mail, google_api_key, subject_text, content], ) if response: gr.Info("Mail gönderildi") else: gr.Warning("HATA! Mail gönderilemedi") demo.launch(share=False)