好的,我试着用smtplib发送一封电子邮件,里面的代码是有效的!但是我不知道怎么把一个主题放进去,我见过其他人在这里谈论它,但是他们用的方法使得你不能在里面放任何文字,所以我在这里问。
此外,发件人是一个gmail帐户,与接收者相同。
import smtplib
import socket
email='xxxxxxxxxx'
password='xxxxxxxxxx'
def sendMail(to, subject, message):
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
print("Connection Status: Connected")
except socket.gaierror:
print("Connection Status: ERROR: Not connected to the internet")
server.ehlo()
server.starttls()
server.login(email, password)
# subject here or something
server.sendmail('text', to, message)
try:
sendMail('xxxxxxxx', 'this is the text')
except smtplib.SMTPAuthenticationError:
print("ERROR: Username or Password are not accepted")发布于 2021-09-01 07:37:39
import smtplib
import socket
message = f'Subject: {SUBJECT}\n\n{TEXT}'
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()https://stackoverflow.com/questions/69009418
复制相似问题