Reputation: 39709
I have following code which successfully sent email using Gmail address. But when i tried to use email account other than Gmail which is one of domain email. It gaves me socket error. Do i need to change something?
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
The email which i am using is [email protected]
. I also tried updating SMTPserver = 'smtp.gmail.com'
to SMTPserver = 'smtpout.secureserver.net'
the smptp of my domain but it also did not work. Please help.
Upvotes: 0
Views: 591
Reputation: 882
When you use SMTPserver='smtp.gmail.com'
try port number as 465, it may work.
Upvotes: 4
Reputation: 2185
May be You have to change conn = SMTP(SMTPserver, 587)
port also with respective to your email server.
Upvotes: 3