如何使用tkinter和zmail发送邮件
时间: 2023-05-11 17:05:20 浏览: 61
你可以使用以下代码来使用tkinter和zmail发送邮件:
```python
import tkinter as tk
import zmail
def send_email():
# 获取输入框中的内容
recipient = recipient_entry.get()
subject = subject_entry.get()
content = content_entry.get("1.0", "end-1c")
# 发送邮件
server = zmail.server("your_email_address", "your_email_password")
mail = {
"subject": subject,
"content": content,
}
server.send_mail(recipient, mail)
# 清空输入框
recipient_entry.delete(0, "end")
subject_entry.delete(0, "end")
content_entry.delete("1.0", "end")
# 创建窗口
window = tk.Tk()
window.title("发送邮件")
# 创建输入框和按钮
recipient_label = tk.Label(window, text="收件人:")
recipient_label.grid(row=0, column=0)
recipient_entry = tk.Entry(window)
recipient_entry.grid(row=0, column=1)
subject_label = tk.Label(window, text="主题:")
subject_label.grid(row=1, column=0)
subject_entry = tk.Entry(window)
subject_entry.grid(row=1, column=1)
content_label = tk.Label(window, text="内容:")
content_label.grid(row=2, column=0)
content_entry = tk.Text(window, height=10)
content_entry.grid(row=2, column=1)
send_button = tk.Button(window, text="发送", command=send_email)
send_button.grid(row=3, column=1)
# 运行窗口
window.mainloop()
```
请注意,您需要将“your_email_address”和“your_email_password”替换为您自己的电子邮件地址和密码。