Skip to content
This repository
Browse code

Even easier setup when using well known e-mail domain

  • Loading branch information...
commit e522d62adc16f3a5b0d1fd587904fc16cd175ced 1 parent 41af151
Andris Reinman authored
4 examples/example_smtp.js
@@ -2,7 +2,9 @@ var nodemailer = require('../lib/nodemailer');
2 2
3 3 // Create a SMTP transport object
4 4 var transport = nodemailer.createTransport("SMTP", {
5   - service: 'Gmail', // use well known service
  5 + //service: 'Gmail', // use well known service.
  6 + // If you are using @gmail.com address, then you don't
  7 + // even have to define the service name
6 8 auth: {
7 9 user: "test.nodemailer@gmail.com",
8 10 pass: "Nodemailer123"
13 lib/engines/smtp.js
... ... @@ -1,11 +1,17 @@
1 1 var wellKnownHosts = require("../wellknown"),
2   - simplesmtp = require("simplesmtp");
  2 + simplesmtp = require("simplesmtp"),
  3 + wellKnownDomains = {};
3 4
4 5 // Expose to the world
5 6 module.exports = SMTPTransport;
6 7
7 8 // Convert Wellknown keys to lowercase
8 9 wellKnownHosts = Object.keys(wellKnownHosts).reduce(function(lowerCaseKeys, currentKey){
  10 +
  11 + [].concat(wellKnownHosts[currentKey].domains || []).forEach(function(domain){
  12 + wellKnownDomains[domain] = currentKey.toLowerCase().trim();
  13 + });
  14 +
9 15 lowerCaseKeys[currentKey.toLowerCase().trim()] = wellKnownHosts[currentKey];
10 16 return lowerCaseKeys;
11 17 },{});
@@ -78,6 +84,11 @@ SMTPTransport.prototype.initOptions = function(){
78 84 // lets be modest just in case
79 85 this.options.maxConnections = this.options.maxConnections || 5;
80 86
  87 + // detect service from the e-mail address if host is not provided before falling to localhost
  88 + if(!this.options.host && !this.options.port && !this.options.service && this.options.auth && this.options.auth.user){
  89 + this.options.service = wellKnownDomains[(this.options.auth.user || "").toString().split("@").pop().toLowerCase().trim()] || false;
  90 + }
  91 +
81 92 // use well known settings if service is defined
82 93 if((service = this.options.service) && (service = service.toString().toLowerCase().trim()) && wellKnownHosts[service]){
83 94 keys = Object.keys(wellKnownHosts[service]);
24 lib/wellknown.js
@@ -7,26 +7,31 @@ module.exports = {
7 7 host: "smtp.gmail.com",
8 8 secureConnection: true,
9 9 port: 465,
10   - requiresAuth: true
  10 + requiresAuth: true,
  11 + domains: ["gmail.com", "googlemail.com"]
11 12 },
12 13 "Yahoo":{
13 14 host: "smtp.mail.yahoo.com",
14 15 secureConnection: true,
15 16 port: 465,
16   - requiresAuth: true
  17 + requiresAuth: true,
  18 + domains: ["yahoo.com"]
17 19 },
18 20 "Hotmail":{
19 21 host: "smtp.live.com",
20 22 port: 587,
21   - requiresAuth: true
  23 + requiresAuth: true,
  24 + domains: ["hotmail.com", "outlook.com"]
22 25 },
23 26 "hot.ee":{
24 27 host: "mail.hot.ee",
25   - requiresAuth: true
  28 + requiresAuth: true,
  29 + domains: ["hot.ee"]
26 30 },
27 31 "mail.ee":{
28 32 host: "smtp.mail.ee",
29   - requiresAuth: true
  33 + requiresAuth: true,
  34 + domains: ["mail.ee"]
30 35 },
31 36 "SES":{
32 37 host: "email-smtp.us-east-1.amazonaws.com",
@@ -44,7 +49,8 @@ module.exports = {
44 49 "iCloud":{
45 50 host:"smtp.mail.me.com",
46 51 port: 587,
47   - requiresAuth: true
  52 + requiresAuth: true,
  53 + domains: ["me.com", "mac.com"]
48 54 },
49 55 "SendGrid":{
50 56 host: "smtp.sendgrid.net",
@@ -65,13 +71,15 @@ module.exports = {
65 71 host: "smtp.yandex.ru",
66 72 port: 465,
67 73 secureConnection: true,
68   - requiresAuth: true
  74 + requiresAuth: true,
  75 + domains: ["yandex.ru"]
69 76 },
70 77 "Mail.Ru":{
71 78 host: "smtp.mail.ru",
72 79 port: 465,
73 80 secureConnection: true,
74   - requiresAuth: true
  81 + requiresAuth: true,
  82 + domains: ["mail.ru"]
75 83 },
76 84 "DynectEmail":{
77 85 host:"smtp.dynect.net",
2  package.json
... ... @@ -1,7 +1,7 @@
1 1 {
2 2 "name": "nodemailer",
3 3 "description": "Easy to use module to send e-mails, supports unicode and SSL/TLS",
4   - "version": "0.3.41",
  4 + "version": "0.3.42",
5 5 "author" : "Andris Reinman",
6 6 "maintainers":[
7 7 {

0 comments on commit e522d62

Please sign in to comment.
Something went wrong with that request. Please try again.