Forum Stats

  • 3,769,505 Users
  • 2,252,970 Discussions
  • 7,875,061 Comments

Discussions

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

pauljohny100
pauljohny100 Member Posts: 184

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

But  when i hard code the variable

receipt = '[email protected]'

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 = '[email protected]'

password = 'zzz#123'

msg = MIMEMultipart('mixed')

sender = '[email protected]'

import cx_Oracle;

conn=cx_Oracle.connect('subv100/[email protected]/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 = '[email protected]'

     msg['Subject'] = ''

     msg['From'] = sender

     msg['To'] = '[email protected]'

     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 = '[email protected]'

password = 'zzz#123'

msg = MIMEMultipart('mixed')

sender = '[email protected]'

import cx_Oracle;

conn=cx_Oracle.connect('subv100/[email protected]/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/[email protected]/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 ?