Domanda

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 domains@smoothplus.com . 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.

È stato utile?

Soluzione

May be You have to change conn = SMTP(SMTPserver, 587) port also with respective to your email server.

Altri suggerimenti

When you use SMTPserver='smtp.gmail.com' try port number as 465, it may work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top