문제

Okay, I'm getting frustrated with the lack of resources for GAE boilerplate especially since it's a wee bit complex as far as directory structure, so I'm coming here.

Anyways, I have this contact form which I adapted from the contact.html template provided with the boilerplate. I'm not interested in making user registration available to the visitor, I just want a very simple contact form with Full name, Email address, and Message. As far as I can tell, the form itself is working, as I did not change any code from the boilerplate:

    <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>

The problem I'm having is I can't get it to send the email to the email address I'm wanting it to. The only file I can tell to change so I can achieve sending it to d*******@gmail.com is the config.py file, and I tried changing this:

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

Starting at line 24 ending at line 26 but no luck. Is there another configuration file I'm supposed to change? Btw, the exact directory of the config.py file I changed is C:\Users\*****\Desktop\Projects\******\boilerplate\config.py

도움이 되었습니까?

해결책

What does the log say?

In GAE, the sender of emails must be either a registered admin in the appengine console or a logged in google user. So if none of these conditions are true your email will not be sent.

Here's how I do it and it works for me (after having registered the email address as an admin in the appengine admin console):

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()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top