【发布时间】:2015-02-16 13:12:04
【问题描述】:
我正在尝试使用 Ruby 从控制台发送电子邮件。
def send_email
yourdomain = 'whatever.com' # my site
youraccountname = 'whatever@gmail.com' # my smtp gmail account
yourpassword = 'whatever' # my smtp gmail account
fromaddress = 'whatever@gmail.com'
toaddress = 'whatever@hotmail.com' #recipient
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start(yourdomain, youraccountname, yourpassword, :login) do
smtp.send_message(report_msg, fromaddress, toaddress)
end
end
def report_msg
@msg ||= ["subject: #{report_subject}", report_body.html_safe].join("\n")
end
report_body 有点复杂,但最重要的是 - 它有这样的东西:
"[<a href='http://www.google.com'>some text</a>]".html_safe
“Google”只是示例链接。当收件人收到此链接时,链接将显示为原始文本。喜欢<a href='http://www.google.com'>some text</a>。不知道如何使它工作。
不知道这是否重要,但电子邮件正文没有<html> 或<body> 标签。并且没有 html 标头。
【问题讨论】: