如何发送没有html格式的Email

How to send Email sending without html format

我在 rails 中使用 mailer.It 发送电子邮件 successfully.But 它发送的方式不是 proper.It 发送 html 这样的标签

Sent mail to xxx (3.6ms)
Date: Mon, 09 Nov 2015 14:53:15 +0500
From: from@example.com
To: xxx
Message-ID: <56406d0b15b8e_6f03f8d3408607861097@des-0071.mail>
Subject: Password Reset
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit

<html>
<body>
<p>Hello </p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><a href="/api/password_edit.LnWq8Y018rU0MGGZpDfHjA">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

</body>
</html>

文件是 password_reset.html.erb

在rails控制台中,您可以实际看到html标签。但在真实的电子邮件中,您看不到那些 HTML 标签。尝试 运行 不使用控制台,但 运行 实际上你希望它如何调用。使用 mailcatchergem 查看电子邮件的真实结果。

简而言之,您可以这样安装 运行:

  1. gem install mailcatcher
  2. 运行 mailcatcher 到你的 bash.
  3. 转到浏览器:http://localhost:1080/

然后你可以看到这样image

电子邮件客户端将在用户收到电子邮件后呈现这些标签,您将看不到任何标签。在 Rails 中,电子邮件模板的处理方式与视图非常相似。如果您将 <html></html> 之间的所有内容保存在文件中并在浏览器中打开,这就是电子邮件对用户的显示效果。

您还想在您的电子邮件 link 中发送一个绝对路径,这是您现在拥有的一个相对 link 并且如果用户在您的网站外单击它(从电子邮件客户端)它不会起作用。