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.
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'
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 an app.yaml
file and another service called second-service
with second-service.yaml
.
Added the following to both app.yaml
& second-service.yaml
files
inbound_services:
- mail
second-service.yaml
Note that my python file here is called second.py
. It handles traffic routed to second-service
- url: /_ah/mail/.+
script: second.app
app.yaml
Note that my python file here is called ``main.py```.- url: /_ah/mail/.+
script: main.app
main.py
and second.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'
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