Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble sending html in email with Pony gem

I've found this gem to be a great and easy way to send mail but I can't seem to send any html in it. If I write the following:

Pony.mail(
  :to => message[:to],
  :from => @account[:from],
  :subject => message[:subject],
  :content_type => 'text/html',
  :html_body => "<h1>hey there!</h1>",
  :via => :smtp,
  :smtp => {
    :host => MY_HOST,
    :port => PORT,
    :auth => AUTH,
    :user => MY_USER,
    :password => MY_PASSWORD,
    :tls => true } )

The code above send a mail but the message appears to be empty in gmail.

Any help would be greatly appreciated on this.

Thanks.

like image 615
Gerard Avatar asked Jun 16 '10 10:06

Gerard


1 Answers

You need to specify content type as a key inside a headers key. And then you can just put your HTML in a body, not an html_body.

Example:

Pony.mail(
  :to => message[:to],
  :from => @account[:from],
  :subject => message[:subject],
  :headers => { 'Content-Type' => 'text/html' },
  :body => "<h1>hey there!</h1>",
  :via => :smtp,
  :smtp => {
    :host => MY_HOST,
    :port => PORT,
    :auth => AUTH,
    :user => MY_USER,
    :password => MY_PASSWORD,
    :tls => true } )
like image 192
ferrous26 Avatar answered Oct 30 '22 13:10

ferrous26