|
| 1 | +# Official EmailJS SDK for Node.js |
| 2 | + |
| 3 | +SDK for [EmailJS.com](https://www.emailjs.com) customers. |
| 4 | +\ |
| 5 | +Use you EmailJS account for sending emails. |
| 6 | + |
| 7 | +[](https://codecov.io/gh/emailjs-com/emailjs-react-native) |
| 8 | +[](https://www.npmjs.com/package/@emailjs/react-native) |
| 9 | + |
| 10 | +## Disclaimer |
| 11 | + |
| 12 | +This is a NodeJS-only version, otherwise use |
| 13 | +- [Browser SDK](https://www.npmjs.com/package/@emailjs/browser) |
| 14 | +- [Flutter SDK](https://pub.dev/packages/emailjs) |
| 15 | +- [Node.js SDK](https://pub.dev/packages/@emailjs/nodejs) |
| 16 | +- [REST API](https://www.emailjs.com/docs/rest-api/send/) |
| 17 | + |
| 18 | +## Links |
| 19 | + |
| 20 | +[Official SDK Docs](https://www.emailjs.com/docs) |
| 21 | + |
| 22 | +## Intro |
| 23 | + |
| 24 | +EmailJS helps to send emails directly from your code. |
| 25 | +No large knowledge is required – just connect EmailJS to one of the supported |
| 26 | +email services, create an email template, and use our SDK |
| 27 | +to trigger an email. |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +Install EmailJS SDK using [npm](https://www.npmjs.com/): |
| 32 | + |
| 33 | +```bash |
| 34 | +$ npm install @emailjs/react-native |
| 35 | +``` |
| 36 | + |
| 37 | +***Note***: By default, API requests are disabled for non-browser applications. |
| 38 | +You need to activate them through [Account:Security](https://dashboard.emailjs.com/admin/account/security). |
| 39 | + |
| 40 | +## FAQ |
| 41 | + |
| 42 | +#### API calls are disabled for non-browser applications |
| 43 | +You need to activate API requests |
| 44 | +through [Account:Security](https://dashboard.emailjs.com/admin/account/security). |
| 45 | + |
| 46 | +## Examples |
| 47 | + |
| 48 | +### ECMAScript modules |
| 49 | + |
| 50 | +**send email** |
| 51 | + |
| 52 | +```js |
| 53 | +import emailjs from '@emailjs/react-native'; |
| 54 | + |
| 55 | +const templateParams = { |
| 56 | + name: 'James', |
| 57 | + notes: 'Check this out!', |
| 58 | +}; |
| 59 | + |
| 60 | +emailjs |
| 61 | + .send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>', templateParams, { |
| 62 | + publicKey: '<YOUR_PUBLIC_KEY>', |
| 63 | + }) |
| 64 | + .then( |
| 65 | + (response) => { |
| 66 | + console.log('SUCCESS!', response.status, response.text); |
| 67 | + }, |
| 68 | + (err) => { |
| 69 | + console.log('FAILED...', err); |
| 70 | + }, |
| 71 | + ); |
| 72 | +``` |
| 73 | + |
| 74 | +**init (optional)** |
| 75 | + |
| 76 | +```js |
| 77 | +import emailjs from '@emailjs/react-native'; |
| 78 | + |
| 79 | +// set Public Key as global settings |
| 80 | +emailjs.init({ |
| 81 | + publicKey: '<YOUR_PUBLIC_KEY>', |
| 82 | +}); |
| 83 | + |
| 84 | +emailjs.send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>').then( |
| 85 | + (response) => { |
| 86 | + console.log('SUCCESS!', response.status, response.text); |
| 87 | + }, |
| 88 | + (err) => { |
| 89 | + console.log('FAILED...', err); |
| 90 | + }, |
| 91 | +); |
| 92 | +``` |
| 93 | + |
| 94 | +**await/async with EmailJS error handler** |
| 95 | + |
| 96 | +```js |
| 97 | +import emailjs, { EmailJSResponseStatus } from '@emailjs/react-native'; |
| 98 | + |
| 99 | +try { |
| 100 | + await emailjs.send( |
| 101 | + '<YOUR_SERVICE_ID>', |
| 102 | + '<YOUR_TEMPLATE_ID>', |
| 103 | + {}, |
| 104 | + { |
| 105 | + publicKey: '<YOUR_PUBLIC_KEY>', |
| 106 | + }, |
| 107 | + ); |
| 108 | + console.log('SUCCESS!'); |
| 109 | +} catch (err) { |
| 110 | + if (err instanceof EmailJSResponseStatus) { |
| 111 | + console.log('EMAILJS FAILED...', err); |
| 112 | + return; |
| 113 | + } |
| 114 | + |
| 115 | + console.log('ERROR', err); |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +### CommonJS modules |
| 120 | + |
| 121 | +**send email** |
| 122 | + |
| 123 | +```js |
| 124 | +const emailjs = require('@emailjs/react-native'); |
| 125 | + |
| 126 | +var templateParams = { |
| 127 | + name: 'James', |
| 128 | + notes: 'Check this out!', |
| 129 | +}; |
| 130 | + |
| 131 | +emailjs |
| 132 | + .send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>', templateParams, { |
| 133 | + publicKey: '<YOUR_PUBLIC_KEY>', |
| 134 | + }) |
| 135 | + .then( |
| 136 | + function (response) { |
| 137 | + console.log('SUCCESS!', response.status, response.text); |
| 138 | + }, |
| 139 | + function (err) { |
| 140 | + console.log('FAILED...', err); |
| 141 | + }, |
| 142 | + ); |
| 143 | +``` |
0 commit comments