Ger*_*Ger 7 ruby html-email pony
我发现这个宝石是一种发送邮件的好方法,但我似乎无法发送任何HTML.如果我写下面的内容:
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 } )
Run Code Online (Sandbox Code Playgroud)
上面的代码发送邮件但邮件在gmail中显示为空.
任何帮助将不胜感激.
谢谢.
小智 15
您需要将内容类型指定为标题键内的键.然后你可以把你的HTML放在一个正文中,而不是一个html_body.
例:
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 } )
Run Code Online (Sandbox Code Playgroud)