I don't believe I'm using Django... This is just a program i wrote in Python 2.7 and i just uploaded it here. I'll post both the function and the place in main where the function is called:
def send_mail(send_from, send_to, subject, text, login, password, files=[], server = 'smtp.gmail.com:587'):
'''A function to connect to a gmail account and send an email with the attached, fully filled out DRQ.'''
assert type(send_to)==list
assert type(files)==list
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = COMMASPACE.join(send_to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach( MIMEText(text) )
for f in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part)
smtp = smtplib.SMTP(server)
smtp.starttls()
smtp.login(login, password)
smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
send_from = 'prattdrqdonotreply@gmail.com'
send_to = ['scboxdesign@gmail.com']
subject = itemnum
if(sendEmail == 'Y' or sendEmail == 'y'):
text = raw_input('Write anything that you would like to include in the body of your email: ')
files = [drqsave]
login = 'gmailusername'
password = 'password'
if(sendEmail == 'Y' or sendEmail == 'y'):
send_mail(send_from, send_to, subject, text, login, password, files)
Mind you, I am not a professional coder by any means.. I have just finished my second comp sci class in college and we learned python so i only have a basic understanding thus far.