使用mailgun将相同的消息发送到不同的电子邮件

时间:2018-10-05 19:29:04

标签: ruby-on-rails ruby mailgun

我需要将同一封邮件发送到三封不同的电子邮件。
我该怎么办?
像每个使用一个?

这是可行的,但是如果我只是在视图中添加一个字段,例如:

<div class="form-group">
  <%= label_tag(:to, "Recipient's email address") %>
  <%= email_field_tag :to, "", class: "form-control" %>
</div> 

我得到了错误:

  

400错误的请求

由于参数。
我的HTML是:

<h1>Send a message with Mailgun</h1>
<% flash.each do |key, value| %>
<div class="alert alert-success"><%= value %></div>
<% end %>

<%= form_tag(:action => 'create')%>

<div class="form-group">
<%= label_tag(:to, "Recipient's email address") %>
<%= email_field_tag :to, "", class: "form-control" %>
</div>

<div class="form-group">
<%= label_tag(:body, "Message") %>
<%= text_area_tag :body, "", class: "form-control" %>
</div>

<%= submit_tag("Send", :class => "btn btn-primary") %>

我的模特:

class HomeController < ApplicationController
def index
end

def create

# Get message value from form
@message = params

  # First, instantiate the Mailgun Client with your API key
  mg_client = Mailgun::Client.new ('7a9c4084f-b0aacd0-a2b65624')

  # Define your message parameters
  html_output = render_to_string template: "notifier/send_email"
  message_params = {:from    => 'postmaster@sandbox671e4d0f627c.mailgun.org',
                    :to      => @message[:to],
                    :subject => 'Mailgun message via API',
                    :text    => @message[:body],
                    :html    => html_output.to_str,
                    "o:tag"  => 'test'}

  # Send your message through the client
  mg_client.send_message ('sandboxe6fb741ddb25.mailgun.org'), message_params

  # Redirect on success
  redirect_to root_path, notice: 'Message was sent.'

   end
  end

0 个答案:

没有答案