如何将 link 插入电子邮件
How to insert link into email
我正在尝试使用 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" 只是示例 link。当收件人收到此消息时,link 将显示为原始文本。喜欢<a href='http://www.google.com'>some text</a>
。不知道如何让它工作。
不知道这是否重要,但是电子邮件 body 没有 <html>
或 <body>
标签。没有 html headers.
您可能需要将 mimetype 设置为 "text/html" 或 "text/html; charset=utf-8"
我正在尝试使用 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" 只是示例 link。当收件人收到此消息时,link 将显示为原始文本。喜欢<a href='http://www.google.com'>some text</a>
。不知道如何让它工作。
不知道这是否重要,但是电子邮件 body 没有 <html>
或 <body>
标签。没有 html headers.
您可能需要将 mimetype 设置为 "text/html" 或 "text/html; charset=utf-8"