Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Even easier setup when using well known e-mail domain

  • Loading branch information...
commit e522d62adc16f3a5b0d1fd587904fc16cd175ced 1 parent 41af151
@andris9 authored
View
4 examples/example_smtp.js
@@ -2,7 +2,9 @@ var nodemailer = require('../lib/nodemailer');
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
- service: 'Gmail', // use well known service
+ //service: 'Gmail', // use well known service.
+ // If you are using @gmail.com address, then you don't
+ // even have to define the service name
auth: {
user: "test.nodemailer@gmail.com",
pass: "Nodemailer123"
View
13 lib/engines/smtp.js
@@ -1,11 +1,17 @@
var wellKnownHosts = require("../wellknown"),
- simplesmtp = require("simplesmtp");
+ simplesmtp = require("simplesmtp"),
+ wellKnownDomains = {};
// Expose to the world
module.exports = SMTPTransport;
// Convert Wellknown keys to lowercase
wellKnownHosts = Object.keys(wellKnownHosts).reduce(function(lowerCaseKeys, currentKey){
+
+ [].concat(wellKnownHosts[currentKey].domains || []).forEach(function(domain){
+ wellKnownDomains[domain] = currentKey.toLowerCase().trim();
+ });
+
lowerCaseKeys[currentKey.toLowerCase().trim()] = wellKnownHosts[currentKey];
return lowerCaseKeys;
},{});
@@ -78,6 +84,11 @@ SMTPTransport.prototype.initOptions = function(){
// lets be modest just in case
this.options.maxConnections = this.options.maxConnections || 5;
+ // detect service from the e-mail address if host is not provided before falling to localhost
+ if(!this.options.host && !this.options.port && !this.options.service && this.options.auth && this.options.auth.user){
+ this.options.service = wellKnownDomains[(this.options.auth.user || "").toString().split("@").pop().toLowerCase().trim()] || false;
+ }
+
// use well known settings if service is defined
if((service = this.options.service) && (service = service.toString().toLowerCase().trim()) && wellKnownHosts[service]){
keys = Object.keys(wellKnownHosts[service]);
View
24 lib/wellknown.js
@@ -7,26 +7,31 @@ module.exports = {
host: "smtp.gmail.com",
secureConnection: true,
port: 465,
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["gmail.com", "googlemail.com"]
},
"Yahoo":{
host: "smtp.mail.yahoo.com",
secureConnection: true,
port: 465,
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["yahoo.com"]
},
"Hotmail":{
host: "smtp.live.com",
port: 587,
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["hotmail.com", "outlook.com"]
},
"hot.ee":{
host: "mail.hot.ee",
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["hot.ee"]
},
"mail.ee":{
host: "smtp.mail.ee",
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["mail.ee"]
},
"SES":{
host: "email-smtp.us-east-1.amazonaws.com",
@@ -44,7 +49,8 @@ module.exports = {
"iCloud":{
host:"smtp.mail.me.com",
port: 587,
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["me.com", "mac.com"]
},
"SendGrid":{
host: "smtp.sendgrid.net",
@@ -65,13 +71,15 @@ module.exports = {
host: "smtp.yandex.ru",
port: 465,
secureConnection: true,
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["yandex.ru"]
},
"Mail.Ru":{
host: "smtp.mail.ru",
port: 465,
secureConnection: true,
- requiresAuth: true
+ requiresAuth: true,
+ domains: ["mail.ru"]
},
"DynectEmail":{
host:"smtp.dynect.net",
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "nodemailer",
"description": "Easy to use module to send e-mails, supports unicode and SSL/TLS",
- "version": "0.3.41",
+ "version": "0.3.42",
"author" : "Andris Reinman",
"maintainers":[
{
Please sign in to comment.
Something went wrong with that request. Please try again.