Я создал программу на python для автоматической отправки электронных писем.Это должно быть довольно просто.
Я перепробовал несколько разных методов, и после часа экспериментирования с новыми и незнакомыми модулями я наконец-то пришел к коду, который у меня сейчас есть.
import smtplib, ssl
port = 587
server_name = 'smtp.gmail.com'
email = 'not_telling_you@my_email.com'
recipient = 'not_telling_you1@my_email.com'
message = 'Hello world'
context = ssl.create_default_context()
print('Having trouble? Go to "accounts.google.com > settings > less secure app access > turn on access > on" when using a gmail account. It is not recommended to do this with your normal account.')
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Log in"
self.hi_there["command"] = self.login
self.hi_there.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def login(self):
server = smtplib.SMTP(server_name, port)
print('Connecting to server...')
server.ehlo()
server.starttls()
server.ehlo()
print('Successfully connected to', server_name, 'through port', port)
print('Logging in...')
server.login(email,'****************')
print('Successfully logged into', email)
server.sendmail(email, recipient, message)
print('Successfully sent', message, 'from', email, 'to', recipient)
root = tk.Tk()
app = Application(master=root)
app.mainloop()
Он должен просто отправлять электронную почту автоматически, когда пользователь нажимает кнопку входа (я не удосужился изменить то, что он говорит, я строю из старой программы).Он попадает в отправленный ящик электронной почты отправителя, но получатель так и не получает письмо.