【问题标题】:How to insert link into email如何在电子邮件中插入链接
【发布时间】: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”只是示例链接。当收件人收到此链接时,链接将显示为原始文本。喜欢&lt;a href='http://www.google.com'&gt;some text&lt;/a&gt;。不知道如何使它工作。

不知道这是否重要,但电子邮件正文没有&lt;html&gt;&lt;body&gt; 标签。并且没有 html 标头。

【问题讨论】:

    标签: ruby email


    【解决方案1】:

    您可能需要将 mimetype 设置为“text/html”或“text/html; charset=utf-8”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 2017-10-21
      • 1970-01-01
      • 2015-11-16
      • 1970-01-01
      相关资源
      最近更新 更多