这个代码工作,并发送给我一个电子邮件就好了: import smtplib #SERVER = "localhost" FROM = 'monty@python.com' TO = ["jon@mycompany.com"] # must be a list SUBJECT = "Hello!" TEXT = "This message was sent with Python's smtplib." # Prepare actual message message = """\ From: %s To: %s Subject: %s %s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) # Send the mail server […]
经过多次search,我找不到如何使用smtplib.sendmail发送给多个收件人。 问题是每次发送邮件邮件标题将显示包含多个地址,但实际上只有第一个收件人会收到电子邮件。 问题似乎是, email.Message模块需要与smtplib.sendmail()函数不同的东西。 简而言之,要发送给多个收件人,您应该将标题设置为由逗号分隔的电子邮件地址的string。 sendmail()参数to_addrs应该是电子邮件地址列表。 from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText import smtplib msg = MIMEMultipart() msg["Subject"] = "Example" msg["From"] = "me@example.com" msg["To"] = "malcom@example.com,reynolds@example.com,firefly@example.com" msg["Cc"] = "serenity@example.com,inara@example.com" body = MIMEText("example email body") msg.attach(body) smtp = smtplib.SMTP("mailhost.example.com", 25) smtp.sendmail(msg["From"], msg["To"].split(",") + msg["Cc"].split(","), msg.as_string()) smtp.quit()
我一直在寻找很多,我仍然不知道如何从python的不同类访问variables…在这种情况下,我想访问variablesself.v从PageOne类到PageTwo类..请帮助我 这是我的代码… import tkinter as tk import smtplib TITLE_FONT = ("Helvetica", 18, "bold") class SampleApp(tk.Tk): def __init__(self): tk.Tk.__init__(self) container = tk.Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (StartPage, PageOne, PageTwo): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StartPage) def show_frame(self, c): frame = self.frames[c] frame.tkraise() […]