我目前正在尝试使用 Flutter 制作一些移动代码。我正在尝试使用 gcloud 库 dart 将数据发布/订阅到 GCP Cloud Pub/Sub。这是 main.dart 的代码:
import 'dart:io';
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:http/http.dart' as http;
import 'package:gcloud/db.dart';
import 'package:gcloud/storage.dart';
import 'package:gcloud/pubsub.dart';
import 'package:gcloud/service_scope.dart' as ss;
import 'package:gcloud/src/datastore_impl.dart' as datastore_impl;
Future<int> main() async {
// Read the service account credentials from the file.
var jsonCredentials = new File('path/file.json').readAsStringSync();
var credentials = new auth.ServiceAccountCredentials.fromJson(jsonCredentials);
// Get an HTTP authenticated client using the service account credentials.
var scopes = []
..addAll(PubSub.SCOPES);
var client = await auth.clientViaServiceAccount(credentials, …
Run Code Online (Sandbox Code Playgroud) dart google-cloud-platform gcloud google-cloud-pubsub flutter
我在 Heroku 上部署了一个 Django 应用程序。在其中一节中,我使用 SMTP Gmail 设置向用户发送电子邮件。当我在本地运行项目时,电子邮件发送成功,但在 Heroku 上部署的项目上却发送失败。
我在 Stackoverflow 上看到了许多其他答案,但没有一个能解决我的问题。我已在我的 Google 帐户上启用了 2FA,并生成了一个应用程序密码,并在我的设置文件中使用该密码。其他开发者不建议打开allow_less_secure_app选项
我的settings.py
文件电子邮件设置-
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER2')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS2')
Run Code Online (Sandbox Code Playgroud)
我views.py
对处理邮件的看法-
def index(request)
if request.method == 'POST':
form = MyForm(request.POST)
if form.is_valid():
message = form.cleaned_data['message']
email = form.cleaned_data['email']
subject = "You got a message"
thoughts = "{} by {}".format(message,email)
recipients = ['xyz@gmail.com']
sender = 'abc@gmail.com'
send_mail(subject, thoughts, sender ,recipients,fail_silently=False)
return …
Run Code Online (Sandbox Code Playgroud)