我为我的网站构建了一个自定义邀请应用程序。要激活邀请,您必须点击发送到您的电子邮件的链接。
然后问题就变成了,我的电子邮件发送功能无法将字符串作为消息发送,如下所示:
custom_message = "http://www.something.com%s" % invite.get_absolute_url()
经过多次测试,问题似乎与 . :
,因为没有它,一切似乎都可以正常工作。
我不需要冒号,因为我可以把整个都http://
去掉。但我很好奇为什么将这个字符串传递给我的函数时该send_custom_email()
函数不起作用
作为参考,这是我的电子邮件发送功能:
def send_custom_email(recipient, custom_message):
to = 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:' + 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()
一个测试:
>>> 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!
尽管发送了电子邮件,但消息未呈现