1

I am implementing email_auth package in flutter to sent out the OTP code for verification. After successfully implementing it, here is the email I got. Verification Code

There is nothing wrong with it, but I would like to customize the message so that it looks better to new users.

Here is my code

    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())
        ],
      ),
    );
  }
}

Does anyone have experience customizing what's being sent on email? Thank you.

smbbb
  • 95
  • 1
  • 9

1 Answers1

2

as described in the package you need to setup your own server and modify the html Template

https://github.com/saran-surya/email_auth_node/blob/main/custom/index.html

Here are the instructions:

https://saran-surya.github.io/email-auth-node/

DEFL
  • 907
  • 7
  • 20
  • Silly me, I will take a look. Sorry for "wasting" your time to have to look up for me. – smbbb Jan 29 '22 at 21:05
  • Don't worry its totally fine. Happens to all of us. If I can assist you let me know – DEFL Jan 30 '22 at 13:12
  • So I wanna use this in the project's repository that I have been working on, which means it would need to be in a branch, but it would create a whole new repository. Is there a solution for it? – smbbb Mar 24 '22 at 05:47
  • Sorry not sure what you mean. Could you clarify? – DEFL Mar 25 '22 at 09:02
  • I am using this package to a project I have been working on. I wanna customize the email layout and when I tried the second link, it would create a whole new repository, but as you know, I would like that to be in my project's repository so that I can modify the design? – smbbb Mar 25 '22 at 14:41
  • I would suggest just downloading the code from the second link and copy paste in your current repository. There you can modify it. Does that work for you? – DEFL Mar 26 '22 at 08:44
  • Also @user16249392, I am looking into the issue for using the package with an existing server. Kindly provide me some time. Here is the link to the enhancement ticket. https://github.com/saran-surya/email_auth_node/issues/31 – SARAN SURYA Mar 31 '22 at 03:32
  • I am the one who emailed you earlier. I have submitted an issue just now. – smbbb Mar 31 '22 at 05:08