我可以在 google-app-engine 的默認服務接收 eamil,地址是 [email protected],但我需要發送到特定服務,而不是默認服務,我該怎么做,下面是我的代碼,在此先感謝。
應用程式.yaml
runtime: python39
app_engine_apis: true
service: target-service
inbound_services:
- mail
- mail_bounce
處理代碼: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'
uj5u.com熱心網友回復:
剛剛在 Python2.7 中測驗過,但我相信它應該在 Python3 中作業(關于郵件部分的原理應該是相同的,但可能需要對其他地方進行一些調整)
我有一個
default帶有檔案的服務和app.yaml另一個名為second-service.second-service.yamlapp.yaml在&second-service.yaml檔案中添加了以下內容
inbound_services:
- mail
- 將此添加到
second-service.yaml注意我的 python 檔案在這里被稱為second.py. 它處理路由到的流量second-service
- url: /_ah/mail/.
script: second.app
- 將此添加到
app.yaml注意我這里的 python 檔案稱為 ``main.py```。
- url: /_ah/mail/.
script: main.app
- 將以下內容添加到
main.py和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'
- 為了進行測驗,我向以下地址發送了電子郵件,它們僅由各自的服務接收。
注意:我使用-dot-而不是.用于多服務位。
a) support@second-service-dot-<project_id>.appspotmail.com
b) support@<project_id>.appspotmail.com
最后一點:我只有在service: second-service里面second-service.yaml
uj5u.com熱心網友回復:
為了能夠在 App Engine 中使用特定服務,您需要在 中指定它app.yaml:
service: service-name
此外,如果您計劃在您的應用程式中使用多個服務,這里有一個檔案可以用來構建您的應用程式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/444829.html
上一篇:NodeJS中的強化學習?
