weaver / node-mail

This SMTP client library for Node.JS helps you send email safely and easily.
113 stars 17 forks source link

Modified node-mail to send text/html #6

Closed paulshapiro closed 13 years ago

paulshapiro commented 14 years ago

Hi guys,

Wasn't sure where to post this.

I made a simple modification to lib/mail/message.js like this to allow for HTML to be sent via node-mail. Node-mail was the only solution that I could get working for some reason.

// [Message Format](http://tools.ietf.org/html/rfc5322)
function Message(headers) {
  if (!(this instanceof Message))
    return new Message(headers);

  this._sender = null;
  this._recipients = null;
  this.headers = {};
  this._body = '';

  if (headers) {
    for (var key in headers)
      this.headers[util.titleCaseHeader(key)] = headers[key];
  }

  if (!('Date' in this.headers))
    this.headers['Date'] = util.date();

  if (!('Content-Type' in this.headers))
    this.headers['Content-Type'] = "text/html";
}

Message.prototype.HEADERS = ['Date', 'Sender', 'From', 'To', 'Cc', 'Subject', 'Content-Type'];

Hope this helps or is accepted into the code.

Regards

weaver commented 14 years ago

Hey Paul,

Does it work to pass in a Content-Type header to .message()? For example:

mail.message({
  from: 'sender@example.net',
  to: ['recipient@somewhere.org'],
  subject: 'Hello from Node.JS',
  'Content-Type': 'text/html'
})
// ... more methods here ...

Best wishes,

-Ben

JeffreyM commented 13 years ago

Yes this works though the value must be a string. For example, the following will work fine: 'Mime-Version': '1.0'

This, however, will not: 'Mime-Version': 1.0

Cheers J

weaver commented 13 years ago

Thanks for reporting this, I'm going to close it since there's a way to give node-mail the headers it needs. Mime support will be added in an upcoming release. Thanks!