0 Replies Latest reply on Nov 30, 2018 8:08 AM by pauljohny100

    Need help .. i am trying to put variable from database to a memory variable but this works strange

    pauljohny100

      I am using python to pull db value from oracle and put it to  a variable .

      But  when i hard code the variable

      receipt = 'pauljohny200@yahoo.com'

      But when i  fetch the value from db  I dont recive the email.

      Below is example of the code.

      The below code works when ithe value of receipttent is hard coded.

       

      #!/usr/bin/python

       

      import smtplib

      from email.mime.text import MIMEText

      from email.mime.multipart import MIMEMultipart

       

      username = 'paul@magazinecrm.com'

      password = 'zzz#123'

      msg = MIMEMultipart('mixed')

      sender = 'paul@magazinecrm.com'

      import cx_Oracle;

      conn=cx_Oracle.connect('subv100/oracle@localhost/xe')

      cur=conn.cursor()

      cur.execute("select company,nvl(addressedas,'Sir/Madamme'),balance,email  from  contact where nvl(balance,0) > 0 and contacttype = 'ADVERTISER'")

       

       

      for line in cur:

       

       

           zzz = line[1]

           aaa = line[3]

           recipient = 'pauljohny101@yahoo.com'

           msg['Subject'] = ''

           msg['From'] = sender

           msg['To'] = 'pauljohny101@yahoo.com'

           text_message = MIMEText('Just keeping informed you need to make payment.', 'plain')

           html_message = MIMEText('Just keeping informed you need ot mkae payment.', 'html')

           msg.attach(text_message)

           mailServer = smtplib.SMTP('mail.smtp2go.com', 2525) # 8025, 587 and 25 can also be used.

           mailServer.ehlo()

           mailServer.starttls()

           mailServer.ehlo()

           mailServer.login(username, password)

           mailServer.sendmail(sender, recipient, msg.as_string())

           mailServer.close()

       

       

       

           print(zzz)

           print(aaa)      

       

       

      cur.close()

      conn.close()

       

       

       

      But the below code doenst work ..

      Which is quite strange.

      #!/usr/bin/python

       

      import smtplib

      from email.mime.text import MIMEText

      from email.mime.multipart import MIMEMultipart

       

      username = 'paul@magazinecrm.com'

      password = 'zzz#123'

      msg = MIMEMultipart('mixed')

      sender = 'paul@magazinecrm.com'

      import cx_Oracle;

      conn=cx_Oracle.connect('subv100/oracle@localhost/xe')

      cur=conn.cursor()

      cur.execute("select company,nvl(addressedas,'Sir/Madamme'),balance,email  from  contact where nvl(balance,0) > 0 and contacttype = 'ADVERTISER'")

       

       

      for line in cur:

       

       

           zzz = line[1]

           aaa = line[3]

           recipient = aaa

           msg['Subject'] = ''

           msg['From'] = sender

           msg['To'] = aaa

           text_message = MIMEText('Just keeping informed you need to make payment.', 'plain')

           html_message = MIMEText('Just keeping informed you need ot mkae payment.', 'html')

           msg.attach(text_message)

           mailServer = smtplib.SMTP('mail.smtp2go.com', 2525) # 8025, 587 and 25 can also be used.

           mailServer.ehlo()

           mailServer.starttls()

           mailServer.ehlo()

           mailServer.login(username, password)

           mailServer.sendmail(sender, recipient, msg.as_string())

           mailServer.close()

       

       

       

           print(zzz)

           print(aaa)      

       

       

      cur.close()

      conn.close()

       

      But this code doesnt work which is quite strange.

      import cx_Oracle;

      conn=cx_Oracle.connect('subv100/oracle@localhost/xe')

      cur=conn.cursor()

      cur.execute("select company,nvl(addressedas,'Sir/Madamme'),balance,email  from  contact where nvl(balance,0) > 0 and contacttype = 'ADVERTISER'")

       

       

      for line in cur:

       

       

           zzz = line[1]

           aaa = line[3]

           recipient = aaa

           msg['Subject'] = ''

           msg['From'] = sender

           msg['To'] = aaa

           text_message = MIMEText('Just keeping informed you need to make payment.', 'plain')

           html_message = MIMEText('Just keeping informed you need ot mkae payment.', 'html')

           msg.attach(text_message)

           mailServer = smtplib.SMTP('mail.smtp2go.com', 2525) # 8025, 587 and 25 can also be used.

           mailServer.ehlo()

           mailServer.starttls()

           mailServer.ehlo()

           mailServer.login(username, password)

           mailServer.sendmail(sender, recipient, msg.as_string())

           mailServer.close()

       

       

       

           print(zzz)

           print(aaa)      

       

       

      cur.close()

      conn.close()

       

       

      Kindly help me understand why will the code behave differently

           aaa = line[3]

           recipient = aaa

      The above code linE[3] pUTS Value into aa a which goes to recepitent field

      Is this correct .

      What can i be doing wrong ?