I am able to receive eamil at the default service of google-app-engine, the address is [email protected], but I need to send to a specific service, not the default service, how can I do that, below is my code, thanks in advance.
app.yaml
runtime: python39
app_engine_apis: true
service: target-service
inbound_services:
- mail
- mail_bounce
handle code:main.py
from flask import Flask, request
from google.appengine.api import wrap_wsgi_app
from google.appengine.api import mail
app = Flask(__name__)
app.wsgi_app = wrap_wsgi_app(app.wsgi_app, use_deferred=True)
@app.route('/_ah/mail/<path>', methods=['POST'])
def receive_mail(path):
mail_message = mail.InboundEmailMessage(request.get_data())
print("called")
return 'Success'
CodePudding user response:
To be able to use a specific service in App Engine, you need to specify it in the app.yaml
:
service: service-name
Additionally if you are planning to use multiple services in your app, here's a documentation you can use to structure your app.
CodePudding user response:
Just tested this in Python2.7 but I believe it should work in Python3 (the principle should be the same when it comes to the mail part but might require a few tweaks for the other places)
I have a
default
service with anapp.yaml
file and another service calledsecond-service
withsecond-service.yaml
.Added the following to both
app.yaml
&second-service.yaml
files
inbound_services:
- mail
- Added this to
second-service.yaml
Note that my python file here is calledsecond.py
. It handles traffic routed tosecond-service
- url: /_ah/mail/.
script: second.app
- Added this to
app.yaml
Note that my python file here is called ``main.py```.
- url: /_ah/mail/.
script: main.app
- Added the following to both
main.py
andsecond.py
@app.route('/_ah/mail/<path>', methods=['POST'])
def receive_mail(path):
mail_message = mail.InboundEmailMessage(request.get_data())
logging.info(mail_message.subject)
return 'Success'
- For testing, I sent emails to the addresses below and they were only received by their respective services.
Note: I used -dot-
and not .
for the multi-service bit.
a) support@second-service-dot-<project_id>.appspotmail.com
b) support@<project_id>.appspotmail.com
Final bit: I only have service: second-service
within second-service.yaml