Python 使用smtplib发送电子邮件
我有以下代码,成功地发送电子邮件使用Gmail地址。但当我尝试使用Gmail以外的电子邮件帐户时,Gmail是域电子邮件的一种。它使我感到套接字错误。我需要改变什么吗Python 使用smtplib发送电子邮件,python,smtplib,Python,Smtplib,我有以下代码,成功地发送电子邮件使用Gmail地址。但当我尝试使用Gmail以外的电子邮件帐户时,Gmail是域电子邮件的一种。它使我感到套接字错误。我需要改变什么吗 def sendEmail(userName, password, subject, content, toEmail, fromEmail): print 'Sending email to: %s' % toEmail SMTPserver = 'smtp.gmail.com' sender =
def sendEmail(userName, password, subject, content, toEmail, fromEmail):
print 'Sending email to: %s' % toEmail
SMTPserver = 'smtp.gmail.com'
sender = fromEmail
destination = [toEmail]
USERNAME = userName
PASSWORD = password
text_subtype = 'plain'
try:
content = content
subject = subject
msg = MIMEText(content, text_subtype)
msg['Subject'] = subject
msg['From'] = sender
conn = SMTP(SMTPserver, 587)
conn.ehlo()
conn.starttls()
conn.ehlo()
conn.login(USERNAME, PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
print 'Email sent successfully.'
finally:
conn.close()
except Exception, exc:
raise exc
我使用的电子邮件是
domains@smoothplus.com
。我还尝试将SMTPserver='smtp.gmail.com'
更新为SMTPserver='smtpout.secureserver.net'
我的域的smtp,但它也不起作用。请帮助。可能您必须更改conn=SMTP(SMTPserver,587)
端口以及相应的电子邮件服务器。当您使用SMTPserver='SMTP.gmail.com'
尝试端口号as 465时,它可能会工作。除了例外,它有什么作用,exc:raise exc?我第一次在错误记录器中保存异常,但为了测试(问题在哪里),我引发了异常。右-587仅用于“传出服务器”,是一项相当“新发明”。传统上,端口25用于此操作,因此可能您的提供商的服务器不支持此操作(尚未)。尝试使用端口25
,但出现此错误(简短说明)SMTP错误:连接错误10060
@Aamir Adnan Dot尝试任何随机设置最好从管理电子邮件服务器的系统管理员处获得正确的设置,他可以为您提供正确的服务器nama和端口号或其他设置,如ssl或需要或不需要。我应该向系统管理员询问什么信息?已获取smtpserver地址。我需要端口吗?这里是infosmtpout.secureserver.net 80353525465(SSL)
所以它需要SSL?然后我使用了smtplib import SMTP_SSL中的,并删除了STARTTLS/EHLO命令。然后它给我一个错误,说先运行connect