Email is one of the oldest message sending technique present today. The email was created in 1972 by Ray Tomlinson. So now you know a little bit about the history of the email, and if you want to know more about the history of the email please refer to this link.
Now let’s talk about how to send email using flutter. For this, we need an external dart package called mailer.
Install the mailer package
- First, add the following line to the pubspec.yaml file in your flutter application. (The version may change, at the time you check this article)
- After that you must install the package, just write the following code in your command line (for this to work you must have set an environmental variable for flutter). But keep in mind for some code editors like VS Code, this line will be automatically completed, therefore it would be better to check the documentation for your code editor to learn more about that.
- As the final step of the installation, you need to import the package to the relevant dart file that you want to use.
For more information about the installation and other details about the mailer package please refer to the link.
Using the mailer package
Now let’s dive into the code!
Here I am creating a Gmail server for sending emails. Though we can create other servers, creating a gmaiGmailver is the easiest so today I’m going to concentrate on that one.
Here I have used two important keywords, async and await. If you want to learn more about those keywords please refer to this link.
Here I have shown only a few things in the mailer package, you can also send attachments and HTML contents.
Github link to the code shown in the article
You can find the code shown in the article, in this GitHub link
This is the end of the article, and before I finish this article I want to say, if I had made any mistakes or if there is an easy way to do this please add a comment below about it.
Thank you and HAPPY CODING!
Less secure apps & your Google Account
If “Less secure app access” is on for your account Because less secure apps can make your account more vulnerable…
Refer to this article and allow Less Secure app access in your google account, otherwise, Google would not let you send emails through their servers.
Hope this helps and HAPPY CODING!