jeudi 2 avril 2015

Send a Subscription email, verify if user clicked in "Confirm Subscription" and send an email if he clicked... in same function

I have this function below and in this function Im trying to do 4 things:


-> create a topic


-> send a Confirm Subscription Email


-> verify if user clicked in "Confirm subscription"


-> send an email if user clicked in "Confirm Subscription"


The problem here is that, Im always getting the message "Pending Confirmation, please confirm subscription in you email and then we will sent you an email...".


Even when I confirm the subscription Im always getting this message, and I need to execute the code again to send the email.


But my idea was to send email without execute the code again, so I have a while loop to check the subscription status and when its diferent than "PendingConfirmation" I want to send the email that is this line:


publication = c.publish(topicArnResult, message, subject=message_subject



def createTopicSendConfirmSubscriptionSendEmail(msg):

# here i get topic name and email from my msg dictonary
topicname = msg['topico']

emailaddress = msg['email']

# I create a topic
topicarn = c.create_topic(topicname)
# And send a "Subscription Confirmation" email
# so the user can click in "Confirm Subscription" to start receive emails
subscription = c.subscribe(topicArnResult, "email", emailaddress)

# And then I want to send a email to the user,
# but only when he clicks in "Confirm subscription" link
# in the email sent in previous line


getSubscriptions = c.get_all_subscriptions_by_topic(topicArn)
# here i get the subscription email status
getSubscriptionEmailStatus = getSubscriptions[...]
message = "test message"
message_subject = "test subject"

# while SubscriptionEmailStatus is "PendingConfirmation" I wan to show a message
while getSubscriptionEmailStatus == "PendingConfirmation":
raw_input("Pending Confirmation,
please confirm subscription in your email
and then we will sent you an email...")
# here i get the subscription email status
getSubscriptionEmailStatus = getSubscriptions[...]

# here I send an email but just when the status != "PendingConfirmation"
publication = c.publish(topicArnResult, message, subject=message_subject)


I tried to explain the issue in the best way but maybe is a bit confused, if you dont understand please say.





Aucun commentaire:

Enregistrer un commentaire