我发现这个 gem 是发送邮件的一种非常简单的方法,但我似乎无法在其中发送任何 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 } )
上面的代码发送了一封邮件,但邮件在 gmail 中似乎是空的。
任何帮助将不胜感激。
谢谢。
最佳答案
您需要将内容类型指定为标题键内的键。然后您可以将 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 } )
关于ruby - 使用 Pony gem 在电子邮件中发送 html 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3052520/