Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit 3c25000

Browse files
committed
Improve example to be actually working example
1 parent 457cfda commit 3c25000

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

source/api/email.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,23 @@ function with addition of `packageSettings` key which will pass in package setti
106106
set in your app settings (if any). It is up to you what you do in that function
107107
as it will override the original sending function.
108108

109-
Example:
109+
Here is a simple example with Mailgun:
110110
```javascript
111111
import { Email } from 'meteor/email'
112+
import { Log } from 'meteor/logging'
113+
import Mailgun from 'mailgun-js'
112114

113-
Email.customTransport = (options) => {
115+
Email.customTransport = (data) => {
114116
// `options.packageSettings` are settings from `Meteor.settings.packages.email`
115117
// The rest of the options are from Email.send options
116-
customApi.send({ from: options.packageSettings.fromOverride || options.from, to: options.to, message: options.html || options.text });
118+
const mailgun = Mailgun({ apiKey: data.packageSettings.mailgun.privateKey, domain: 'mg.mygreatapp.com' })
119+
120+
// Since the data object that we recieve already includes the correct key names for sending
121+
// we can just pass it to the mailgun sending message.
122+
mailgun.messages().send(data, (error, body) => {
123+
if (error) Log.error(error)
124+
if (body) Log.info(body)
125+
})
117126
}
118127
```
119128

0 commit comments

Comments
 (0)