def sendPromotionalEmailCuteFriends101(userid): # Being saved in email logging as action item 101 l = top_admires(userid) if len(l) < 2: return if min(l[0].values()[0], l[1].values()[0]) < 2: return s = sendgrid.Sendgrid('pratikpoddar', 'P1jaidadiki', secure=True) userinfo = UserTomonotomo.objects.get(userid=userid) friend1info = UserTomonotomo.objects.get(userid=l[0].keys()[0]) friend2info = UserTomonotomo.objects.get(userid=l[1].keys()[0]) contextdict = {} subject = userinfo.first_name + ", your friends find " + friend1info.first_name + " and " + friend2info.first_name + " attractive" contextdict['teaserline'] = subject contextdict['mailheading'] = subject contextdict['mailcontent'] = "Hey "+userinfo.first_name+", Hope you are doing well. Your friends find " + friend1info.first_name + " and " + friend2info.first_name + " attractive. They are trending in your friend network on tomonotomo. You can also secretly indicate that you admire some friend of friend. If he/she also feels the same way, you two would be connected. Best of Luck!" plaintext_message = contextdict['mailcontent'] html_message = dbutils.prepareEmail(contextdict, l[0].keys()[0], l[1].keys()[0], friend1info.get_full_name(), friend2info.get_full_name()) message = sendgrid.Message(("*****@*****.**","Tomonotomo"), subject, plaintext_message, html_message) # add a recipient message.add_to(userinfo.email, userinfo.get_full_name()) # use the SMTP API to send your message s.smtp.send(message) #message.add_to('*****@*****.**', 'Pratik Poddar') #s.smtp.send(message) emaillogging = UserEmail(userid=userid, fofid=l[0].keys()[0], friendid=l[1].keys()[0], action=101) emaillogging.save() return
smtp_server = 'email-smtp.us-east-1.amazonaws.com' smtp_username = '******' smtp_password = '******' smtp_port = '587' smtp_do_tls = True fromaddr = 'Arya from Tomonotomo <*****@*****.**>' toaddrs = '*****@*****.**' contextdict = {} subject = "A friend of your friend thinks you are cute!" contextdict['teaserline'] = subject contextdict['mailheading'] = subject contextdict['mailcontent'] = """Hey, A friend of your friend thinks you are cute. We have kept the identity confidential. We are a friend of friend dating website and it is getting huge traction in France, Spain and India. To figure out who is finding you cute, register on Tomonotomo - http://www.tomonotomo.com. Cheers! ;) True love is rare, and it's the only thing that gives life real meaning.""" html_message = dbutils.prepareEmail(contextdict, '', '', '', '', spam=True) conn = boto.connect_ses(aws_access_key_id=smtp_username,aws_secret_access_key=smtp_password) def send_ses(fromaddr, subject, html_message, toaddrs, conn): """Send an email via the Amazon SES service. Example: send_ses('[email protected], 'greetings', "Hi!", '[email protected]) Return: If 'ErrorResponse' appears in the return message from SES, return the message, otherwise return an empty '' string.