google app engine - Python : smtplib sendmail function -
i have activation mail sending script follows.
#!/usr/bin/python __author__ = 'amyth arora (***@gmail.com)' import smtplib import string import sys import random email.mimetext import mimetext def generate_activation_key(size=64, chars=string.ascii_lowercase + string.digits): return ''.join(random.choice(chars) x in range(size)) def generate_activation_url(key): return 'http://www.example.com/users/activate/' + key def activate(name, to_addr): sender, reciever = 'mymail@gmail.com', to_addr act_url = generate_activation_url(generate_activation_key()) main_mssg = """ dear %s, thakyou creating account example.com. 1 click away using example account. please click following link verify email address , activate account. please note, must complete step become registered member of example. need visit url once in order activate account. ============================ activation link below: ============================ %s if facing problems activating account please contact our support team @ support@example.com best regards, example team """ % (name, act_url) message = mimetext(main_mssg) message['from'] = 'example <' + sender + '>' message['to'] = reciever message['mime-version'] = '1.0' message['content-type'] = 'text/html' message['subject'] = 'activate example account' try: smtpobj = smtplib.smtp('smtp.gmail.com', 587) smtpobj.set_debuglevel(1) # swith on/off debug mode smtpobj.ehlo() smtpobj.starttls() smtpobj.ehlo() smtpobj.login('mymail@gmail.com', 'mypass') smtpobj.sendmail(sender, reciever, message.as_string()) smtpobj.close() return act_url except: return none def main(argv): if len(argv) != 2: sys.exit(1) activate(argv[0], argv[1]) if __name__ == '__main__': main(sys.argv[1:]) the script works fine have tried through command line :
./scriptname 'reciepent name' 'reciepent@gmail.com' however want call activation script within 1 of application handlers this.
import activation act_key = activation.activate('reciepent name', 'reciepent@gmail.com') but when script returns none. can figure out how fix ?
app engine not allow users send emails using smtplib library. instead need use api provided. documentation can found here: https://developers.google.com/appengine/docs/python/mail
Comments
Post a Comment