File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 4747 print(error.toString());
4848}
4949```
50+
51+ ** init (optional)**
52+ ``` dart
53+ import package:emailjs/emailjs.dart
54+
55+ // set Public Key as global settings
56+ EmailJS.init('<YOUR_PUBLIC_KEY>');
57+
58+ try {
59+ // send the email without dynamic variables
60+ await EmailJS.send('<YOUR_SERVICE_ID>','<YOUR_TEMPLATE_ID>');
61+ print('SUCCESS!');
62+ } catch (error) {
63+ print(error.toString());
64+ }
65+ ```
Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+ import 'package:emailjs/emailjs.dart' ;
3+
4+ void main () {
5+ runApp (const App ());
6+ }
7+
8+ class App extends StatelessWidget {
9+ const App ({super .key});
10+
11+ @override
12+ Widget build (BuildContext context) {
13+ return MaterialApp (
14+ title: 'Flutter Demo EmailJS' ,
15+ theme: ThemeData (
16+ primarySwatch: Colors .orange,
17+ ),
18+ home: const HomePage (title: 'Flutter Demo EmailJS' ),
19+ );
20+ }
21+ }
22+
23+ class HomePage extends StatefulWidget {
24+ const HomePage ({super .key, required this .title});
25+ final String title;
26+
27+ @override
28+ State <HomePage > createState () => _HomePageState ();
29+ }
30+
31+ class _HomePageState extends State <HomePage > {
32+ void _sendEmail () async {
33+ try {
34+ await EmailJS .send (
35+ '<YOUR_SERVICE_ID>' ,
36+ '<YOUR_TEMPLATE_ID>' ,
37+ {
38+ 'user_email' : 'hi@example.com' ,
39+ 'message' : 'Hi' ,
40+ },
41+ '<YOUR_PUBLIC_KEY>' ,
42+ );
43+ print ('SUCCESS!' );
44+ } catch (error) {
45+ print (error.toString ());
46+ }
47+ }
48+
49+ @override
50+ Widget build (BuildContext context) {
51+ return Scaffold (
52+ appBar: AppBar (
53+ title: Text (widget.title),
54+ ),
55+ body: Center (
56+ child: Column (
57+ mainAxisAlignment: MainAxisAlignment .center,
58+ children: < Widget > [
59+ const Text (
60+ 'Press "Send Email" to send email' ,
61+ ),
62+ ElevatedButton (
63+ onPressed: _sendEmail, child: const Text ('Send Email' )),
64+ ],
65+ ),
66+ ),
67+ );
68+ }
69+ }
You can’t perform that action at this time.
0 commit comments