【问题标题】:Send a plain text email with an embedded <a> tag in mailgun在 mailgun 中发送带有嵌入 <a> 标签的纯文本电子邮件
【发布时间】:2016-03-29 18:15:34
【问题描述】:

我正在尝试在通过 mailgun 发送的电子邮件文本中嵌入 &lt;a&gt; 链接。正确的语法是什么?

RestClient.post "https://api:#{ENV['MAILGUN_SECRET']}"\
  "@api.mailgun.net/v3/#{ENV['MAILGUN_DOMAIN']}/messages",
  :from => "Mailgun <mailgun@#{ENV['MAILGUN_DOMAIN']}>",
  :to => "#{@lead.email}",
  :subject => "Test",
  :text => "Here is the message, here(http://www.foo.com) is the link"

【问题讨论】:

    标签: html ruby-on-rails email mailgun


    【解决方案1】:

    我认为您不能发送带有 HTML 的“文本”电子邮件,您必须选择一个 我喜欢将我所有的电子邮件都发送为 HTML

    这是我的邮件的样子:

    class SomeMailer < ActionMailer::Base
      def email_method(post_id, lead_id)
        @post = Post.find(post_id)
        @lead = Lead.find(lead_id)
        mail(
            :from => "Email Sender<info@example.com>",
            :to =>   @lead.email,
            :reply_to => 'Email Sender<info@example.com>',
            :subject => "Test"
        )
      end
    end
    

    现在这是有趣的部分。在app/views 中创建一个名为SomeMailer 的文件夹,这样你最终会得到app/views/some_mailer

    现在在该目录中创建一个名为 email_method.html.erb 的文件,其中包含您的 html,例如:

      Here is the message, here(<a href="http://www.foo.com"> foo.com </a>) is the link
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 2015-01-13
      • 1970-01-01
      • 2020-06-12
      • 2012-04-07
      • 2011-09-28
      相关资源
      最近更新 更多