【发布时间】:2022-01-08 12:52:06
【问题描述】:
我在使用 google smtp 从我的应用程序发送电子邮件时遇到问题。
该应用在我的手机上运行良好,我可以毫无问题地发送电子邮件。
但是当我发布应用程序并且人们开始使用它时,我收到了来自 google 的安全电子邮件,告诉我它已阻止登录尝试。
我什至启用了不太安全的登录。
我应该启用其他设置吗?
这是我发送电子邮件的代码
import RNSmtpMailer from 'react-native-smtp-mailer'
async sendEmail(email: string, htmlBody: string, subject: string) {
try {
var settings = await this.getAppSettings();
if (!settings)
throw "Could not find the smtp settings"
var success = await RNSmtpMailer.sendMail({
mailhost: settings.smtp,
port: settings.port,
ssl: true, // optional. if false, then TLS is enabled. Its true by default in android. In iOS TLS/SSL is determined automatically, and this field doesn't affect anything
username: settings.email,
password: settings.password,
fromName: "NovelManager", // optional
replyTo: undefined, // optional
recipients: email,
bcc: [], // optional
subject: subject,
htmlBody: htmlBody,
attachmentPaths: [], // optional
attachmentNames: [], // required in android, these are renames of original files. in ios filenames will be same as specified in path. In a ios-only application, no need to define it
});
return true;
} catch (error) {
return false;
}
}
这里是 smtp 设置
{
smtp: "smtp.gmail.com",
port: "465",
email: "test@gmail.com", // not the real email
password: "test"
}
【问题讨论】:
-
每个字符串,包括密码、机密等对客户端都是可见的,这包括您的电子邮件和密码。您永远不应该在您的移动应用程序中放置秘密,而应使用发送电子邮件而不将密码泄露给客户端的后端服务器。 rammic.github.io/2015/07/28/hiding-secrets-in-android-apps
-
朋友不是这个问题。所有代码都经过 opfoctad,因此不存在找出设置的问题。并且设置存储在firebase中而不是应用程序中。现在我的问题是当其他人使用该应用程序时,谷歌阻止登录尝试的 smtp。
-
在应用程序中通过 SMTP 发送电子邮件是一个糟糕的设计选择。如果 SMTP 是开放的,电话将一直被用来发送垃圾邮件。寻找替代解决方案。不应直接从设备发送邮件(除非它使用适当的电子邮件客户端并得到用户的明确批准/操作)。
-
当用户忘记密码或创建新帐户时,我使用它来发送电子邮件。我没有服务器,这就是我这样做的原因。这应该不是问题,因为我在 google 中启用了不太安全的登录,但由于某种原因我仍然遇到问题。
-
您最好的选择是创建一个 Firebase 云函数并在那里编写您的 SMTP 代码。