Skip to content

Commit

Permalink
turn wellknown service names case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Andris Reinman committed Nov 24, 2012
1 parent fe87603 commit 99bac04
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
42 changes: 29 additions & 13 deletions README.md
Expand Up @@ -367,24 +367,40 @@ out `Date` or any other unsupported field.
### Well known services for SMTP

If you want to use a well known service as the SMTP host, you do not need
to enter the hostname or port number, just use the `service` parameter (**NB!** case sensitive).
to enter the hostname or port number, just use the `service` parameter

Currently supported services are:

* **"DynectEmail"** for DynECT Email Delivery
* **"Gmail"** for Google Mail
* **"hot.ee"** for www.hot.ee
* **"Hotmail"** for Microsoft Live Hotmail
* **"iCloud"** for Apple iCloud
* **"mail.ee"** for www.mail.ee
* **"Postmark"** for Postmark App
* **"SendGrid"** for SendGrid
* **"SES"** for Amazon SES
* **"Yahoo"** for Yahoo Mail
* **"Zoho"** for Zoho Mail
* **DynectEmail**
* **Gmail**
* **hot.ee**
* **Hotmail**
* **iCloud**
* **mail.ee**
* **Mail.Ru**
* **Mailgun**
* **Postmark**
* **SendGrid**
* **SES**
* **Yahoo**
* **yandex**
* **Zoho**

Predefined service data covers `host`, `port` and secure connection settings,
any other parameters (ie. `auth`) need to be set separately.
any other parameters (ie. `auth`) need to be set separately. Service names are
case insensitive, so using "gmail" instead of "Gmail" is totally fine.

Example:

```javascript
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail", // sets automatically host, port and connection security settings
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
});
```

## E-mail message fields

Expand Down
14 changes: 10 additions & 4 deletions lib/engines/smtp.js
Expand Up @@ -4,6 +4,12 @@ var wellKnownHosts = require("../wellknown"),
// Expose to the world
module.exports = SMTPTransport;

// Convert Wellknown keys to lowercase
wellKnownHosts = Object.keys(wellKnownHosts).reduce(function(lowerCaseKeys, currentKey){
lowerCaseKeys[currentKey.toLowerCase().trim()] = wellKnownHosts[currentKey];
return lowerCaseKeys;
},{});

/**
* <p>Generates a Transport object for SMTP</p>
*
Expand Down Expand Up @@ -45,7 +51,7 @@ function SMTPTransport(options){
* values and also for filling in the well known hosts data if needed.</p>
*/
SMTPTransport.prototype.initOptions = function(){
var keys, key, i, len;
var keys, key, i, len, service;

// provide support for legacy API
if(this.options.use_authentication === false){
Expand Down Expand Up @@ -73,12 +79,12 @@ SMTPTransport.prototype.initOptions = function(){
this.options.maxConnections = this.options.maxConnections || 5;

// use well known settings if service is defined
if(this.options.service && wellKnownHosts[this.options.service]){
keys = Object.keys(wellKnownHosts[this.options.service]);
if((service = this.options.service) && (service = service.toString().toLowerCase().trim()) && wellKnownHosts[service]){
keys = Object.keys(wellKnownHosts[service]);
for(i=0, len=keys.length; i<len; i++){
key = keys[i];
this.options[key] = this.options[key] ||
wellKnownHosts[this.options.service][key];
wellKnownHosts[service][key];
}
}
};
Expand Down
11 changes: 11 additions & 0 deletions lib/wellknown.js
Expand Up @@ -50,6 +50,11 @@ module.exports = {
port: 587,
requiresAuth: true
},
"Mailgun":{
host: "smtp.mailgun.org",
port: 587,
requiresAuth: true
},
"Postmark":{
host: "smtp.postmarkapp.com",
port: 25,
Expand All @@ -61,6 +66,12 @@ module.exports = {
secureConnection: true,
requiresAuth: true
},
"Mail.Ru":{
host: "smtp.mail.ru",
port: 465,
secureConnection: true,
requiresAuth: true
},
"DynectEmail":{
host:"smtp.dynect.net",
port:25,
Expand Down
2 changes: 1 addition & 1 deletion 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.31",
"version": "0.3.32",
"author" : "Andris Reinman",
"maintainers":[
{
Expand Down

0 comments on commit 99bac04

Please sign in to comment.