我有以下代码,它使用 Gmail 地址成功发送了电子邮件。但是,当我尝试使用域电子邮件之一的 Gmail 以外的电子邮件帐户时。它给了我套接字错误。我需要改变什么吗?
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'
我的域的 smptp,但它也没有工作。请帮忙。