Skip to content

Commit

Permalink
simplified 'service' usage
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 22, 2013
1 parent d84c0d2 commit 8b1ae06
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -392,19 +392,30 @@ Currently supported services are:
* **Mailgun**
* **Mandrill**
* **Postmark**
* **QQ**
* **SendGrid**
* **SES**
* **Yahoo**
* **yandex**
* **Zoho**
* **QQ**

Predefined service data covers `host`, `port` and secure connection settings,
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("Gmail",{
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
});
```

or alternatively

```javascript
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail", // sets automatically host, port and connection security settings
Expand Down
4 changes: 3 additions & 1 deletion lib/engines/smtp.js
Expand Up @@ -52,6 +52,8 @@ function SMTPTransport(options){
this.options.host, this.options);
}

SMTPTransport.wellKnownHosts = wellKnownHosts;

/**
* <p>Initializes the SMTP connection options. Needed mostly for legacy option
* values and also for filling in the well known hosts data if needed.</p>
Expand Down Expand Up @@ -126,4 +128,4 @@ SMTPTransport.prototype.sendMail = function(emailMessage, callback){
*/
SMTPTransport.prototype.close = function(callback){
this.pool.close(callback);
};
};
5 changes: 5 additions & 0 deletions lib/transport.js
Expand Up @@ -33,6 +33,11 @@ function Transport(type, options){
this.transportType = (type || "").toString().trim().toUpperCase();
this.dkimOptions = false;

if(!(this.transportType in Transport.transports) && this.transportType.toLowerCase() in SMTPTransport.wellKnownHosts){
this.options.service = this.transportType;
this.transportType = SMTPTransport.wellKnownHosts[this.transportType.toLowerCase()].transport;
}

var constructor = Transport.transports[this.transportType];
if(constructor){
this.transport = new constructor(this.options);
Expand Down
17 changes: 17 additions & 0 deletions lib/wellknown.js
Expand Up @@ -4,100 +4,117 @@

module.exports = {
"Gmail":{
transport: "SMTP",
host: "smtp.gmail.com",
secureConnection: true,
port: 465,
requiresAuth: true,
domains: ["gmail.com", "googlemail.com"]
},
"Yahoo":{
transport: "SMTP",
host: "smtp.mail.yahoo.com",
secureConnection: true,
port: 465,
requiresAuth: true,
domains: ["yahoo.com"]
},
"Hotmail":{
transport: "SMTP",
host: "smtp.live.com",
port: 587,
requiresAuth: true,
domains: ["hotmail.com", "outlook.com"],
tls: {ciphers:'SSLv3'}
},
"hot.ee":{
transport: "SMTP",
host: "mail.hot.ee",
requiresAuth: true,
domains: ["hot.ee"]
},
"mail.ee":{
transport: "SMTP",
host: "smtp.mail.ee",
requiresAuth: true,
domains: ["mail.ee"]
},
"SES":{
transport: "SMTP",
host: "email-smtp.us-east-1.amazonaws.com",
secureConnection: true,
port: 465,
requiresAuth: true
},
"Zoho":{
transport: "SMTP",
host: "smtp.zoho.com",
secureConnection: true,
port: 465,
requiresAuth: true,
authMethod: 'LOGIN'
},
"iCloud":{
transport: "SMTP",
host:"smtp.mail.me.com",
port: 587,
requiresAuth: true,
domains: ["me.com", "mac.com"]
},
"SendGrid":{
transport: "SMTP",
host: "smtp.sendgrid.net",
port: 587,
requiresAuth: true
},
"Mailgun":{
transport: "SMTP",
host: "smtp.mailgun.org",
port: 587,
requiresAuth: true
},
"Postmark":{
transport: "SMTP",
host: "smtp.postmarkapp.com",
port: 25,
requiresAuth: true
},
"yandex":{
transport: "SMTP",
host: "smtp.yandex.ru",
port: 465,
secureConnection: true,
requiresAuth: true,
domains: ["yandex.ru"]
},
"Mail.Ru":{
transport: "SMTP",
host: "smtp.mail.ru",
port: 465,
secureConnection: true,
requiresAuth: true,
domains: ["mail.ru"]
},
"DynectEmail":{
transport: "SMTP",
host:"smtp.dynect.net",
port:25,
requiresAuth: true
},
"Mandrill":{
transport: "SMTP",
host: "smtp.mandrillapp.com",
port: 587,
requiresAuth: true
},
"Mailjet":{
transport: "SMTP",
host: "in.mailjet.com",
port: 587,
requiresAuth: true
},
"QQ":{
transport: "SMTP",
host: "smtp.qq.com",
secureConnection: true,
port: 465,
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.4.3",
"version": "0.4.5",
"author": "Andris Reinman",
"maintainers": [
{
Expand Down

0 comments on commit 8b1ae06

Please sign in to comment.