How to send HTML content in email from net//smtp in ruby? -


pertinent code:

msg = "subject: reset password instructions\n\nhello " + @request_payload["email"] + "!\n\n" +       "a new account has been created @ <a href=\"presentation-layer.dev\">presentation-layer.dev<a>." +        "please go page , click \"forgot password\" set password."       smtp = net::smtp.new 'smtp.gmail.com', 587       smtp.enable_starttls       smtp.start('domain', "email", 'password', :login)         smtp.send_message(msg, 'sender', "recip")       end 

the resulting email has raw text in it. how server evaluate html tags?

to want, should generate mime document. if want right, create multipart mime document have both text , rich-text parts.

you can net::smtp, have add necessary mime header , part dividers document. see "sending email using ruby - smtp" example how.

it's easier use mail gem, supports both, if you're including multiple parts or adding attachments. documentation:

you can create mime emails. there helper methods making multipart/alternate email text/plain , text/html (the common pair) , can manually create other type of mime email.

and farther down in document in "writing , sending multipart/alternative (html , text) email":

mail makes basic assumptions , makes doing common thing simple possible.... (asking lot mail library)

mail = mail.deliver        'nicolas@test.lindsaar.net.au'      'mikel lindsaar <mikel@test.lindsaar.net.au>'   subject 'first multipart email sent mail'    text_part       body 'this plain text'   end    html_part       content_type 'text/html; charset=utf-8'       body '<h1>this html</h1>'   end end 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -