[英]Can you customize what's in the email when you use email_auth to sent OTP? (flutter)
我正在 flutter 中實施 email_auth package 以發送 OTP 代碼進行驗證。 成功實現后,這里是我拿到的email。 驗證碼
它沒有任何問題,但我想自定義消息,以便新用戶看起來更好。
這是我的代碼
class OTP extends StatefulWidget {
//OTP({Key? key}) : super(key: key);
@override
_OTPState createState() => _OTPState();
}
class _OTPState extends State<OTP> {
final TextEditingController _emailController = TextEditingController();
final TextEditingController _optcontroller = TextEditingController();
void sendOTP() async {
EmailAuth emailAuth = new EmailAuth(sessionName: "Test Session");
var res = await emailAuth.sendOtp(
recipientMail: _emailController.value.text, otpLength: 6);
if (res) {
print("Verification Code Sent!");
} else {
print("Failed to send the verification code");
}
}
void verifyOTP() {
EmailAuth emailAuth = new EmailAuth(sessionName: "sessionName");
var res = emailAuth.validateOtp(
recipientMail: _emailController.value.text,
userOtp: _optcontroller.value.text);
if (res) {
print("Email Verified!");
} else {
print("Invalid Verification Code");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text("VERIFY YOUR UNIVERSITY"),
),
body: Column(
children: [
Text("Please enter your",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Text("college/university email address",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Colors.black38,
),
),
SizedBox(
height: 38,
),
TextField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
hintText: "Enter email",
),
),
SizedBox(
height: 10,
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: sendOTP,
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all<Color>(Colors.purple),
backgroundColor:
MaterialStateProperty.all<Color>(Colors.orange),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
),
),
child: Padding(
padding: EdgeInsets.all(14),
child: Text(
'send the code',
style: TextStyle(fontSize: 16),
),
),
),
),
SizedBox(
height: 30,
),
TextField(
controller: _optcontroller,
keyboardType: TextInputType.number,
obscureText: true,
decoration: InputDecoration(
hintText: "Enter the 6 digit code",
labelText: "Verification Code",
),
),
SizedBox(
height: 30.0,
),
ElevatedButton(
child: Text("Verify Code"),
onPressed: () => verifyOTP())
],
),
);
}
}
有沒有人有定制 email 上發送的內容的經驗? 謝謝你。
如 package 中所述,您需要設置自己的服務器並修改 html 模板
https://github.com/saran-surya/email_auth_node/blob/main/custom/index.html
以下是說明:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.