python - Using a colon in a string -
i have built custom invite app site. activate invite must follow link sent email.
the issue becomes, email sending function having problem sending string message looks this:
custom_message = "http://www.something.com%s" % invite.get_absolute_url()
after numerous tests, seems issue has :
, since seems work fine without it.
i don't need colon, leave entirety of http://
out. curious why function won't work when passing string send_custom_email()
function
for reference, my email sending function:
def send_custom_email(recipient, custom_message): = recipient gmail_user = 'someone@gmail.com' gmail_pwd = gmail_pwd smtpserver = smtplib.smtp("smtp.gmail.com",587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(gmail_user, gmail_pwd) header = 'to:' + + '\n' + 'from: ' + gmail_user + '\n' + 'subject:invite link \n' print header unicoded_custom_message = unicode(custom_message) msg = header + unicoded_custom_message smtpserver.sendmail(gmail_user, to, msg) print 'done!' smtpserver.close()
a test:
>>> custom_message ="http://www.somesite.com%s" >>> send_custom_email(recipient='someotherperson@mailinator.com', custom_message=custom_message) to:someone@mailinator.com from: someotherperson@gmail.com subject:invite link done!
although email sent, message doesn't render
the email generated violates format emails:
there has space after key of header , there have 2 newlines separate message:
header = 'to: ' + + '\n' + 'from: ' + gmail_user + '\n' + 'subject: invite link \n\n'
as constructing it, link interpreted email header.
also should consider using django's built-in email function. code vulnerable tp header injections. please read: https://docs.djangoproject.com/en/dev/topics/email/ !
python django python-2.7 django-email
No comments:
Post a Comment