python - Google App Engine 样板 - 联系人模板

标签 python html google-app-engine email contacts

好吧,我对 GAE 样板资源的缺乏感到沮丧,特别是因为它的目录结构有点复杂,所以我来到这里。

无论如何,我有这个联系表格,是根据 contact.html 改编的。模板随样板一起提供。我对向访问者提供用户注册不感兴趣,我只想要一个非常简单的联系表单 Full name , Email address ,和Message 。据我所知,表单本身正在工作,因为我没有更改样板中的任何代码:

    <form id="form_contact" action="{{ url|safe }}" method="post" class="well form-horizontal">
        <fieldset>
            <input type="hidden" name="exception" value="{{ exception|e }}">
            <input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
            {{ macros.field(form.name, label=_("Name"), placeholder=_("Enter your")+" "+_("Name"), class="input-xlarge focused required") }}
            {{ macros.field(form.email, label=_("Email"), placeholder=_("Enter your")+" "+_("Email"), class="input-xlarge focused required email", type="email") }}
            {{ macros.field(form.message, label=_("Message"), class="input-xlarge required", cols="40", rows="8") }}
            <div class="form-actions">
                <button type="submit" class="btn btn-primary">{% trans %}Send Message{% endtrans %}</button>
            </div>
        </fieldset>
    </form>

我遇到的问题是我无法将电子邮件发送到我想要的电子邮件地址。我唯一可以告诉更改的文件,以便我可以将其发送到 d*******@gmail.comconfig.py文件,我尝试更改此:

# contact page email settings
'contact_sender': "l*******@gmail.com",
'contact_recipient': "d*******@gmail.com",

起始于line 24结束于line 26但没有运气。我还需要更改另一个配置文件吗?顺便说一句,config.py 的确切目录我更改的文件是 C:\Users\*****\Desktop\Projects\******\boilerplate\config.py

最佳答案

日志说了什么?

在 GAE 中,电子邮件发件人必须是 appengine 控制台中的注册管理员或登录的 Google 用户。因此,如果这些条件都不成立,您的电子邮件将不会被发送。

以下是我的操作方法,它对我有用(在 appengine 管理控制台中将电子邮件地址注册为管理员之后):

from google.appengine.api import mail

 ...

 message = mail.EmailMessage(sender='Kool Business <info@koolbusiness.com>', subject=article.title)
            message.body = """
            Hello!<br>Now your ad <a href="http://www.koolbusiness.com/vi/%d.html">%s</a> has been out for a week. If you already have sold your product you can remove your ad.<br><br>Some advice to promote your ad:<br>Change + Renew the ad and it will be on top of the list. You can also change text and price.<br>Change the ad if you only want to lower the price or change the ad text<br>Renew so that the ad will be on top if the list. <br><br>Best regards,<br>Koolbusiness.com
            """  % (article.key().id(),article.title)
            message.html = """
            <html><head></head><body>
            Hello!<br>Now your article <a href="http://www.koolbusiness.com/vi/%d.html">%s</a> has been out for a week. If you already have sold your product you can remove your ad.<br><br>Some advice to promote your article:<br>Change + Renew the article and it will be on top of the list. You can also change text and price.<br>Change the article if you only want to lower the price or change the ad text<br>Renew so that the ad will be on top if the list. <br><br>Best regards,<br>Koolbusiness.com
            </body></html>
            """  % (article.key().id(),ad.title)
            message.to=article.email
            message.send()

关于python - Google App Engine 样板 - 联系人模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18817956/

相关文章:

javascript - 如何就地删除跨度?

javascript - 将图像对象作为函数和类参数传递

android - Appengine 云端点客户端生成不生成源 jar 文件

java - 将图像上传到 Google Cloud Storage (Java)

mongodb - 如何在谷歌云计算引擎 VM 实例 (Bitnami) 中查找 mongodb 连接字符串

python - 为什么 (python -m ...) 导致 sys.argv 像 ['-c' , ...]

Python - 从导入 PostgreSQL 的 csv 文件中删除特殊字符

html - 很棒的字体没有加载到我的 apache 中

python - 从 PostgreSQL 获取数据到 Django 并以 html 显示

python - 从远程机器执行长时间运行的配置单元查询