Google 在 react-native 中阻止 smtp
Google blocks smtp in react-native
我在使用 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"
}
好吧,我终于找到了解决方案,那就是使用应用密码而不是简单密码。
我在这里发布解决方案以防有人感兴趣。
我在使用 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"
}
好吧,我终于找到了解决方案,那就是使用应用密码而不是简单密码。
我在这里发布解决方案以防有人感兴趣。