@@ -10,8 +10,10 @@ package to your project by running in your terminal:
1010meteor add email
1111```
1212
13- The server reads from the ` MAIL_URL ` environment variable to determine how to
14- send mail. The ` MAIL_URL ` should reference an
13+ There are two ways on how to setup the package for sending e-mail.
14+
15+ First is to set ` MAIL_URL ` . The server reads from the ` MAIL_URL ` environment
16+ variable to determine how to send mail. The ` MAIL_URL ` should reference an
1517[ SMTP] ( https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol ) server and
1618use the form ` smtp://USERNAME:PASSWORD@HOST:PORT ` or
1719` smtps://USERNAME:PASSWORD@HOST:PORT ` . The ` smtps:// ` form (the ` s ` is for
@@ -21,9 +23,31 @@ prior to being upgraded to TLS/SSL (using `STARTTLS`) typically use port 587
2123(and _ sometimes_ 25) and should use ` smtp:// ` . For more information see the
2224[ Nodemailer docs] ( https://nodemailer.com/smtp/ )
2325
24- If ` MAIL_URL ` is not set, ` Email.send ` outputs the message to standard output
26+ Second, if you are using a one of the [ supported services] ( https://nodemailer.com/smtp/well-known/#supported-services )
27+ you can setup the sending options in your app settings like this:
28+
29+ ``` json
30+ {
31+ "packages" : {
32+ "email" : {
33+ "service" : " Mailgun" ,
34+ "user" : " postmaster@meteor.com" ,
35+ "password" : " superDuperPassword"
36+ }
37+ }
38+ }
39+ ```
40+ The package will take care of the rest.
41+
42+ > If you use a supported service the package will try to match to supported service and use the stored settings instead.
43+ > You can force this by switching protocol like ` smtp ` to the name of the service.
44+ > Though you should only use this as a stop-gap measure and instead set the settings properly.
45+
46+ If neither option is set, ` Email.send ` outputs the message to standard output
2547instead.
2648
49+ > Package setting is only available since Email v2.2
50+
2751{% apibox "Email.send" %}
2852
2953You must provide the ` from ` option and at least one of ` to ` , ` cc ` , and ` bcc ` ;
@@ -69,3 +93,39 @@ if you want to intercept emails sent by core packages like accounts-password
6993or other packages where you can't modify the email code.
7094
7195The hook function will receive an object with the options for Nodemailer.
96+
97+ {% apibox "Email.customTransport" %}
98+
99+ > ` Email.customTransport ` is only available since Email v2.2
100+
101+ There are scenarios when you have your own transport set up, be it an SDK
102+ for your mailing service or something else. This is where ` customTransport `
103+ comes in. If you set this function all sending events will be passed to it
104+ (after ` hookSend ` is run) with an object of the options passed into ` send `
105+ function with addition of ` packageSettings ` key which will pass in package settings
106+ set in your app settings (if any). It is up to you what you do in that function
107+ as it will override the original sending function.
108+
109+ Here is a simple example with Mailgun:
110+ ``` javascript
111+ import { Email } from ' meteor/email'
112+ import { Log } from ' meteor/logging'
113+ import Mailgun from ' mailgun-js'
114+
115+ Email .customTransport = (data ) => {
116+ // `options.packageSettings` are settings from `Meteor.settings.packages.email`
117+ // The rest of the options are from Email.send options
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+ })
126+ }
127+ ```
128+
129+ > Note that this also overrides the development display of messages in console
130+ > so you might want to differentiate between production and development for
131+ > setting this function.
0 commit comments