简体   繁体   English

使用smtplib发送电子邮件不再起作用

[英]Sending email using smtplib doesn't work anymore

So yesterday I had this bit of code written out and it worked perfectly fine, but today it's not sending e-mails anymore. 所以昨天我写出了这段代码,它工作得很好,但是今天它不再发送电子邮件了。 Can someone explain why? 有人可以解释为什么吗?

import smtplib

SERVER = 'owa.server.com'
FROM = 'noreply@server.com'
TO = ['person@gmail.com', '1112223344@vtext.com']

name = 'Mr. Man'
SUBJECT = 'Recent Information for: %s' % (name)
TEXT = "Dear " +name+ ",\n\nHello.\n\nSincerely,\nOur Guys Here"

message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

server = smtplib.SMTP(SERVER, 587)
server.ehlo()
server.starttls()
server.ehlo
server.login('noreply@server.com', 'password')
server.sendmail(FROM, TO, message)
server.quit()

This code is a working snippet. 该代码是一个有效的代码段。 I wasn't getting the e-mails in my personal gmail account because gmail was sending it to the spam folder. 我没有在我的个人gmail帐户中收到电子邮件,因为gmail会将其发送到垃圾邮件文件夹。 I checked to see if it works at my office account, and it did just fine. 我检查了一下是否可以在我的办公室帐户上使用,效果还不错。

import smtplib

# Specifying the from and to addresses

fromaddr = 'fromuser@gmail.com'
toaddrs  = 'to@gmail.com'

# Writing the message (this message will appear in the email)

msg = 'Enter you message here'

# Gmail Login

username = 'username'
password = 'password'

# Sending the mail  

server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

Above standard smtp send works with gmail, 高于标准的smtp发送带有gmail的作品,
thus it must be your server(whatever you're using) configuration that is at fault. 因此,它一定是您的服务器(无论使用什么)配置有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM