mailgun / mailgun-ruby Goto Github PK
View Code? Open in Web Editor NEWMailgun's Official Ruby Library
License: Apache License 2.0
Mailgun's Official Ruby Library
License: Apache License 2.0
I get this, when I trying to install through gem install
Fetching: json-1.8.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing mailgun-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:1:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.2 for inspection.
I'm trying to send emails through the mailgun-ruby gem, and it doesn't seem to be merging the fields when sent.
I've been able to reproduce the problem with the following code:
require 'mailgun'
mailgun_client = Mailgun::Client.new("[MAILGUN KEY]")
message = Mailgun::BatchMessage.new(mailgun_client, "mail.domain.com")
message.set_from_address("[email protected]")
message.set_subject("Merge Fields Test")
message.set_text_body("Hello %recipient.first%, this is a test. Your full name is %recipient.first% %last%.")
message.add_recipient(:to, "[email protected]", {"first" => "John", "last" => "Doe"})
message.add_recipient(:to, "[email protected]", {"first" => "Jane", "last" => "Doe"})
message.finalize
Each recipient is getting the non-merged emails with all recipients in the "to" address.
How would one go about using a txt.erb template file for building up a message dynamically?
Attachments in the message_params hash?
Why not a proper list or readme for all these things? Most certainly the basics. Now the only thing online that adds some clarification is a message on mailgun's blog from 2014 and a very short readme?!
I got stuff working somewhat, but I thought the goal of an API should be to make things simpler.
From time to time there is connection error to mailgun service which is not properly handled.
undefined method `response' for #<Errno::ECONNREFUSED: Connection refused - connect(2)>
../shared/bundle/ruby/gems/mailgun-ruby-1.0.2/lib/mailgun.rb:94:in `rescue in get'
../shared/bundle/ruby/gems/mailgun-ruby-1.0.2/lib/mailgun.rb:86:in `get'
../shared/bundle/ruby/gems/mailgun-ruby-1.0.2/lib/mailgun/events/events.rb:50:in `_get'
../shared/bundle/ruby/gems/mailgun-ruby-1.0.2/lib/mailgun/events/events.rb:28:in `get'
I'll try to provide pull request soon
Add functional tests for the Railgun mailer...
I've integrated the client into my rails project and in some of my mailers I've a dynamic list of people to bcc and sometimes that ends up being no one. However whenever a nil/empty value is passed in for the bcc field the mailer bombs out.
How to reproduce the error.
mg_client = Mailgun::Client.new("your-api-key")
mail = Mail::Message.new(to: '[email protected]', cc: ['[email protected]'], bcc: []) # bcc: nil/'' also fails
mg_message = Railgun.transform_for_mailgun(mail)
mg_client.send_message('mg.domain.com', mg_message)
Results in the error below since it has bcc as bcc: [""]
Mailgun::CommunicationError: 400 Bad Request: 'bcc' parameter is not a valid address. please check documentation
I have tried 2 gems for mailgun. Because this one is official so I tried it first and no success delivering emails.
Then I tried https://github.com/jorgemanrubia/mailgun_rails success with 10 seconds.
Maybe docs need some update or its not that good with rails. ( Just my 2 cents )
I am getting this error after commenting out config.action_mailer.mailgun_settings
as it was raising undefined method
mailgun_settings=' for ActionMailer::Base:Class`
Configuration:
The mailgun-ruby-1.1.3.gem on rubygems.org is published with a SHA that does not match the SHA of the file. This could potentially indicate that the contents of the gem have been manipulated in some way.
Bundler cannot continue installing mailgun-ruby (1.1.3).
The checksum for the downloaded `mailgun-ruby-1.1.3.gem` does not match the checksum given by the server. This means the contents of
the downloaded gem is different from what was uploaded to the server, and could be a potential security issue.
To resolve this issue:
1. delete the downloaded gem located at:
`/Users/mwp/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mailgun-ruby-1.1.3/mailgun-ruby-1.1.3.gem`
2. run `bundle install`
If you wish to continue installing the downloaded gem, and are certain it does not pose a security issue despite the mismatching
checksum, do the following:
1. run `bundle config disable.checksum_validation true` to turn off checksum verification
2. run `bundle install`
(More info: The expected SHA256 checksum was "2542b467788ab91479a84617f9aeeb02c1446a52229d80d0a857bed20839d80c", but the checksum
for the downloaded gem was "da81bdb633549e3035252fe1d89f967396bff93d1a7b194c7ba424cbb906c2ad".)
Hello;
i'm completely stuck with the following error Mailgun::Error (Too many recipients, max is 1000)
I'm using the following piece of code to deliver email in batch :
recipients.in_groups_of(500) do |group|
hash = {}
group.compact.each do |r|
hash["#{r["email"]}"] = {name: "#{r["firstname"]}", id: r.id }
end
to = recipients.collect{ |r| r.email }.join(",")
parameters[:to] = to
parameters[:'recipient-variables'] = hash.to_json
Mailgun().messages.send_email(parameters)
end
(i might be missing some pieces but it was working before correctly โ before we reached 1000 total recipients). Parameters contains an array of email adresses, which has been limited to 500. I don't get why I till get this error
Thanks if anyone has clues about it
Best regards
I'm running Rails 5.0.2, and passing options[:reply_to]
to Actionmailer::Base.mail
generates a message object with a Reply-To header, but it doesn't actually get delivered with the reply-to header by mailgun-ruby.
I had to add
mb.reply_to(mail[:reply_to].to_s) if mail[:reply_to].present?
inside build_message_object
in Railgun::Mailer
to get it to work.
I'm trying to send emails in background using delayed_job but for some reason raises Unexpected token at 'Mailgun Magnificent API' error. This only happens in production environment...
Is there any reason 'mailgun/suppressions' is not loaded? I noticed there's also no docs for it but the code exists and works if I require it in myself.
Hello, I have encountered an odd scenario where I am unable to set action_mailer configuration options if I include the mailgun-ruby
gem.
I have a Rails 4.2.7.1 app, where I configure ActionMailer in an initializer. Some of the options I set are the default_url_options
and asset_host
, so that images in our emails have an absolute URL rather than a relative one. Without requiring mailgun-ruby
, emails are generated correctly. As soon as I add gem 'mailgun-ruby'
to my Gemfile, these options are no longer present at the time the email is rendered. This causes an exception to be throw by Rails stating that the default_url_options
are not set.
I did some digging, and found that the root cause is the Railgun::Railtie
, which adds the mailgun
delivery method in before_initialize
hook. I can not find any explanation either in Rails or elsewhere that would explain why adding a delivery method would cause subsequent configuration to not be used. I looked at the Rails initialization events and found nothing that points to a reason why.
I am able to work around this issue by requiring all necessary files except the Railtie. I'm not actually using the mailgun
delivery method, my use case requires me to manually call Railgun.transform_for_mailgun(mail)
and client.send_message('my-domain', message_payload)
, so adding the following to my Gemfile works:
gem 'mailgun-ruby', '~>1.1.4', require: ['mailgun', 'railgun/attachment', 'railgun/errors', 'railgun/mailer', 'railgun/message']
Do you have any thoughts on why this might be happening?
For development, my initializer is effectively this:
# config/initializers/action_mailer.rb
Rails.application.config.action_mailer.default_url_options = { host: 'localhost', :port: 3000, protocol: 'http' }
Rails.application.config.action_mailer.asset_host = 'http://localhost:3000'
Rails.application.config.action_mailer.delivery_method = :smtp
Rails.application.config.action_mailer.smtp_settings = {
address: 'smtp.mailgun.org',
port: 587,
domain: 'my-domain',
user_name: 'username',
password: 'supersecret',
authentication: 'plain',
enable_starttls_auto: true,
}
Rails.application.config.action_mailer.perform_deliveries = false
Can we lower the rest-client
dependency, as it's conflicting with other gems:
In snapshot (Gemfile.lock):
rest-client (= 1.8.0)
In Gemfile:
lob was resolved to 2.5.1, which depends on
rest-client (< 3.0, >= 1.8)
mailgun-ruby (>= 1.1.6, ~> 1.1) was resolved to 1.1.6, which depends on
rest-client (~> 2.0)
stripe was resolved to 1.31.0, which depends on
rest-client (~> 1.4)
stripe was resolved to 1.31.0, which depends on
rest-client (~> 1.4)
I am trying to get counts of certain events.
I am using the following
client.get("mg.mydomain.com/events", { count: 'true', event: 'clicked' })
However, I'm getting the error:
Mailgun::CommunicationError: {
"message": "Unknown parameter: count=['yes']"
}
I tried a few other variations, but could not get anything to work. I am referencing the docs here: http://documentation.mailgun.com/api-campaigns.html#events which I believe should allow for the count
param that I'm using. If I remove "count", the request will go through, but I get the actual events rather than the count. I want the counts to do some stats on my end.
Thank you!
Neal
Thanks for adding the railgun stuff in the last version! Makes my life a lot easier.
One thing I missed initially was the need to include a require 'railgun'
at the top of my production.rb. That's because the railgun stuff doesn't autoload, which makes sense in the case of a non-Rails project.
You could simply add a require 'railgun' if defined?(Rails)
to your mailgun-ruby.rb file and call it a day. But what would be more semantic for Rails would be to implement a Railtie. For now, it would be to simply move this line out of the global context and into an initializer
method instead. But there could be other things that could be added down the line.
I'm more than happy to work up a PR. Just wanted to write this down as an issue first before I forget ๐
It would be nice to manage bounces like : https://github.com/HashNuke/mailgun/blob/master/lib/mailgun/bounce.rb
https://github.com/mailgun/mailgun-ruby/blob/master/lib/mailgun.rb#L87
Should be that @http_client instead?
The docs (MessageBuilder.md
and Messages.md
) say you're supposed to use this syntax: mb_obj.set_delivery_time("tomorrow 8:00AM", "PST");
But the actual def in message_builder.rb
only includes one parameter: def set_delivery_time(timestamp)
and the unit test only tests for one parameter as well.
(I'd issue a pull request, but I'm not familiar enough with Ruby to contribute confidently.)
Hi!
I have just installed the gem in one of our projects and it seems to work fine. However, I've noticed that I cannot get the Message-ID after sending the email. Following the documentation in the README:
mailer = UserNotifier.welcome_email(current_user)
mailer_response = mailer.deliver_now
mailer_response.message_id => Returns the string "id" instead of the message id.
The message is sent through mailgun correctly, however the last line returns the string "id" instead of the message id (i was expecting something like [email protected].
Looking at the code, I could get the right Message-ID by changing just one line of code. Open the file lib/railgun/mailer.rb and change the deliver! function from:
def deliver!(mail)
mg_message = Railgun.transform_for_mailgun(mail)
response = @mg_client.send_message(@domain, mg_message)
if response.code == 200 then
mg_id = response.body['id'] <<-----
mail.message_id = mg_id
end
response
end
to
def deliver!(mail)
mg_message = Railgun.transform_for_mailgun(mail)
response = @mg_client.send_message(@domain, mg_message)
if response.code == 200 then
mg_id = response.to_h['id'] <<-----
mail.message_id = mg_id
end
response
end
and then I get the correct message id.
I'm using ruby 2.4.1 and the latest version of the gem (1.1.6). Any idea what I might be doing wrong?
I appreciate the pastebin-esque method of debugging emails, but it's cumbersome and doesn't help debug with the exact error you have.
Why not have custom exceptions that the library understands and get thrown with the approriate HTTP response?
400 is used as a blanket error - can we at least parse the HTTP error messages from the API and throw a more helpful exception?
Mailgun::Api::InvalidRequest message="Please specify a message body with your request"
The actual exception format needs to be thought through, but this would be a huge improvement over the pastebin.
mailgun-ruby/spec/integration/mailgun_spec.rb
Lines 470 to 473 in 1cb8b87
While trying to make a POST to lists, I receive a 400 Bad Request error. I have tried running the above code straight from your spec and it fails as well. I have other code that is making successful POST requests using the same API key as what is being used to create a list.
Similar to what the mail gem does, for example. It's probably enough to store a copy of the message params, so one can run tests against them.
mail_params = {:to => params[:to],:bcc => params[:bcc],:from => params[:from],:text=> params['body'],:subject => params['subject']}
MAILGUN.send_message(domain,mail_params)
if params[:bcc] is nil, the message wont send, the errror being:
Mailgun::CommunicationError: 400 Bad Request
in ruby, sending nil usually means ignore/skip.
Hi there,
i'm using the Opt-In Handler Method for the mailgun gem. My problem is, that the generated hash is too long, so i have problems to call the url in a mail from a web mail portal like www.web.de. Is there a possibility to manipulate the hash for the Opt In Validation ?
Best regards,
Christian
Hello,
I am configuring my app to work with MailGun, which is awesome.
Without even thinking, I quickly googled for a mailgun
gem, quickly installed it and everything worked straight away. I could send confirmation emails and receive them in my inbox.
I then tried without a gem (or adapter) and it worked pretty much the same way (the email went straight to the trash, actually. Not sure why) so I am wondering. Why the need for an adapter? Should I re-install the adapter gem and do it that way instead?
My code literally changed from:
config.action_mailer.delivery_method = :mailgun
config.action_mailer.smtp_settings = {
:api_key => ENV['MAILGUN_API_KEY'],
:domain => ENV['MAILGUN_DOMAIN']
}
to: (without the extra gem
dependency!)
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:port => ENV['MAILGUN_SMTP_PORT'],
:address => ENV['MAILGUN_SMTP_SERVER'],
:user_name => ENV['MAILGUN_SMTP_LOGIN'],
:password => ENV['MAILGUN_SMTP_PASSWORD'],
:domain => ENV['MAILGUN_DOMAIN'],
:authentication => :plain,
}
Bump rest-client to at least 1.8
Known Security Issues:
rest-client/rest-client#349
rest-client/rest-client#369
When a rails app sends only a text mail, then Railgun sends also the html part (converted from the text part).
The problem, is that all newlines are ignored, when the mail is view in an html capable mail client.
e.g. if the text part of a mail has two lines
first line
second line
then it will be shown as one line in a mail-client with html support.:
first line second line
this code is the cause of the problem
Adding a custom parameter according to the docs:
mb_obj.add_custom_parameter('h:List-Unsubscribe',"<mailto:[email protected]>")
Results in this header in the email:
List-Unsubscribe[]: <mailto:[email protected]>
The added [ ] appears with any custom header and any contents, so that would seem to be a bug.
I am trying to install the gem on Mac and Ubuntu but without success. Multimap is yanked on rubygems.org.
โ test_howitzer_framework gem install mailgun-ruby ruby-2.0.0-p353@test_howitzer_framework
ERROR: While executing gem ... (Gem::UnsatisfiableDependencyError)
Unable to resolve dependency: 'mailgun-ruby (= 1.0.0)' requires 'multimap (~> 1.1)'
Would be nice to see easy rails integration
Something like this: https://github.com/Paxa/mailgun-rails
Any plans to implement it?
I'm consistently getting this error on server startup in an otherwise empty rails project with the following configuration:
ruby 2.3.4
rails 5.2.1
mailgun-ruby 1.1.6
development.rb
config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
api_key: "api key here",
domain: "mailgun domain here"
}
error message
~/.rvm/gems/ruby-2.3.4/gems/actionmailer-5.1.1/lib/action_mailer/base.rb:580:in `method_missing': undefined method `mailgun_settings=' for ActionMailer::Base:Class (NoMethodError)
Did you mean? sendmail_settings
I'm using config.action_mailer.mailgun_settings=
as described in the gem's documentation. Not sure if this is a bug or a configuration issue.
message_builder = Mailgun::MessageBuilder.new
message_builder.add_recipient('h:reply-to', '[email protected]')
should set the reply to. That doesn't work, nor does:
message_builder.add_custom_parameter('h:reply-to', '[email protected]')
The issue here, is if an array of reply-to addresses is posted, then the reply to address does not get set (or at least does not seem to be in gmail).
I'd suggest that either:
(1) Complex_setter and simple_setter should not create arrays of size one.
(2) The MailGun backend that receives these parameters should treat these the same.
Presently there is no good way to set the reply to address. I've resorted to using:
message_builder.message['h:Reply-To'] = '[email protected]'
which feels like a bit of hack.
I would create a PR for (1) if you like.
Given that this hasn't been updated in a year, isn't updated to the v3 API, and the maintainers aren't replying to PRs or issues, I think it would be wise to not give users the idea that this is being maintained.
Please correct me if this is being maintained in some capacity.
I have Rails 5.0.1 using ActionMailer code as follows:
def pdf_quote(proposal)
@proposal = proposal
email_with_name = %("#{@proposal.first_name} #{@proposal.last_name}" <#{@proposal.email}>)
@filename = "QD-#{@proposal.qd_number}_#{@proposal.last_name}.pdf"
attachments[@filename] = {
mime_type: 'application/pdf',
encoding: 'Base64',
content: @proposal.pdf_base64
}
mail(
to: email_with_name,
from: 'Floorbook UK <email address>',
subject: 'Your Personal Flooring Quote is attached',
sent_on: Time.now
)
end
I have tried by hardcoding 'test.pdf' also. I have tried replace flilename: with remoteName inside the hash (as I see th PHP plugin uses remoteName).
No matter what I try the filename does not appear in the JSON in the mailgun logs.
I can however see it in the Rails log. For example, here is the log when I tried using remotename:
----==_mimepart_58acb0bbc5906_b35a3ff9c303fa14374b
Content-Type: application/pdf
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename=QD-1002_McSharry.pdf
remotename: QD-1002_McSharry.pdf
Content-ID: <58acb0bbc8aaf_b35a3ff9c303fa14376d9@Richards-MacBook-Air.local.mail>
%PDF-1.3
Here is the relevant part of the JSON from the mailgun log:
"message": {
"headers": {
"to": "Richard McSharry ",
"message-id": "20170221213251.124698.55612.AAE859F0@sandbox4d05645e78ac4c81b7b542d27c5e87ad.mailgun.org",
"from": "Floorbook UK ",
"subject": "Your Personal Flooring Quote is attached"
},
"attachments": [
{
"filename": "",
"content-type": "application/pdf",
"size": 9004
}
],
"recipients": [
"my email"
],
"size": 11517
},
Right now if the mailgun queue is full (500k emails) you will get an error back.
Error handling should cover this, by either retrying after waiting some seconds or issue an error that says "you may retry in a couple of seconds".
This may even happen on a single email (without batch).
When you use the API for ActionMailer this is even worse as emails are just not sent.
C:\Users\lectricas\Documents\obed18-menu>bundle install
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Could not find gem 'mailgun-ruby (~> 1.0.5) x64-mingw32' in any of the gem
sources listed in your Gemfile or available on this machine.
C:\Users\lectricas\Documents\obed18-menu>]
The Mailgun::BatchMessage
doesn't replace the placeholders in the email.
I'm trying to construct the batch message from a csv file
It works with "%recipient.account_id%"
but not with "%account_id%"
, even thought the documentation states that it should
batch = Mailgun::BatchMessage.new(Mailgun::Client.new, Mailgun.domain)
# pretend that from and subject are set
batch.body_html("<p>%account_id%</p>")
csv_data.each do |d|
batch.add_recipient(:to, d[:email], d.to_h)
end
puts batch.recipient_variables
batch.finalize
Csv data example:
d = {
email: "[email protected]",
account_id: 123
}
The recipient_variables
puts out correct info, however i can't seem to find it in the log and the "%account_id%"
doesn't get replaced
{
"[email protected]" => {
email: "[email protected]",
account_id: 123
}
}
Looks like the same as in #22
Relevant documentation:
http://blog.mailgun.com/the-official-mailgun-ruby-sdk-is-here/
https://github.com/mailgun/mailgun-ruby/blob/master/docs/Messages.md#usage---batch-message
When setting the Reply-To with message builder extra characters are applied to the header:
mb_obj.add_recipient("h:Reply-To", "[email protected]");
or
mb_obj.add_custom_parameter("h:Reply-To", "[email protected]");
You end up with:
Reply-To[]: [email protected]
This breaks setting a Reply-To as it is not honored by any providers.
Could you please make errors more informative?
On multiple occasions (with different reasons), I got:
Mailgun::CommunicationError: undefined method `each_byte' for nil:NilClass
from /Users/zzz/.rvm/gems/ruby-2.2.3/bundler/gems/mailgun-ruby-cae112741ae8/lib/mailgun/client.rb:58:in `rescue in post'
from /Users/zzz/.rvm/gems/ruby-2.2.3/bundler/gems/mailgun-ruby-cae112741ae8/lib/mailgun/client.rb:55:in `post'
from /Users/zzz/.rvm/gems/ruby-2.2.3/bundler/gems/mailgun-ruby-cae112741ae8/lib/mailgun/client.rb:39:in `send_message'
This communication error is absolutely uninformative and there is nothing I can do with it except prying deep inside rest-client
for possible clues.
Hey mailgun team.
The .ruby-version is currently on 2.0.0-0p which is considered end of life. Any plans to bring this up to a more update to date version? Happy to work on it if you'd like.
Cheers,
Aron
When specifying the :message parameter it should write the string passed in this parameter to a file then submit that temp file to the messages.mime endpoint.
Lines 42 to 58 in 1cb8b87
Most of this works correctly, however no matter what you pass in the :message parameter it is not converted to the file correctly, the file is always empty.
This can be replicated using the custom MIME example found on:
https://github.com/mailgun/mailgun-ruby/blob/1cb8b87a68a2d82db544bde7af388a61e3e70059/Snippets.md
Hey guys/gals
Really enjoying the updated library! Thanks for your time building it :)
Found a small (potential) bug. I'm calling create on the webhook client and it's working (verified the webhook is created) however it's returning false without throwing any exception.
If I get time I'll look into it and submit a PR, but for now just thought I'd raise it :)
Thanks!
Aron
so, im running into this issue:
vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- digest/hmac (LoadError)
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from vendor/ruby/2.2.0/gems/mailgun-ruby-1.0.2/lib/mailgun/lists/opt_in_handler.rb:4:in `<top (required)>'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from vendor/ruby/2.2.0/gems/mailgun-ruby-1.0.2/lib/mailgun.rb:7:in `<top (required)>'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from vendor/ruby/2.2.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
from vendor/ruby/2.2.0/gems/rails-mailgun-0.2.0/lib/rails-mailgun.rb:3
looks like digest/hmac
is removed from ruby-2.2.0-preview1: ruby/ruby@24be1f1
Hey there! Really loving the new Mailgun gem - thanks for the good work.
One thing that I'm running into in my testing is that it's annoying to stub Mailgun out every time I hit an action in my app that sends an email. It would be awesome to be able to do something like
Mailgun.enable_test_mode!
in my spec_helper.rb
that would then cause all the client to not actually make requests to Mailgun.
I was thinking about working on this and opening a pull request, but wanted to see your folks' thoughts on it in case you have other suggestions or a better approach before I go down that path.
Thanks!
I'm using the mailgun-ruby gem to send messages through ActionMailer. I'm trying to attach custom headers so I can identify these messages in my web hooks, but the headers don't seem to go through. (When I check the mailgun logs, they aren't there, and they also aren't transmitted in the web hooks.) Here is an example of my method. Any ideas?
def invitation(invitation_id, reminder=false)
@invitation = ProviderInvitation.find(invitation_id)
headers 'X-Mailgun-Variables' => {provider_invitation_id: invitation_id.to_s, mail_type: "provider_invitation"}.to_json
if reminder
mail(to: @invitation.invited_email, from: "Contact <[email protected]>", subject: "Reminder: #{@invitation.sending_provider.name} invited you to join!")
@invitation.update(reminder_sent: true)
else
mail(to: @invitation.invited_email, from: "Contact <[email protected]>", subject: "#{@invitation.sending_provider.name} invited you to join!")
end
end
When you batch send a message with the mailgun-ruby gem, using the Mailgun::BatchMessage
class, every recipient sees themselves and all the other recipients in the To field.
I used this code. I'm using rails, so Action Mailer is responsible for rendering the message:
mail = FooMailer.a_batch_email(recipients)
client = Mailgun::Client.new(ENV["MAILGUN_API_KEY"])
batch_message = Mailgun::BatchMessage.new(client, "mail.community.hackerschool.com")
batch_message.set_from_address(mail.from.first)
batch_message.set_subject(mail.subject)
batch_message.set_text_body(mail.body.to_s)
mail.to.each do |recipient|
batch_message.add_recipient(:to, recipient)
end
batch_message.finalize
The only difference from https://github.com/mailgun/mailgun-ruby/blob/master/Messages.md is that I'm not passing in any recipient variables, but this should be fine because BatchMessage#add_recipient
creates default recipient variables if nothing is passed as a third argument.
Each recipient in mail.to
should receive a copy of the email with only their email address in the To field.
Each recipient in mail.to
receives an email with everyone in mail.to
in the To field.
Using the API directly by following the instructions in the docs works as expected.
Running the following lines will cause an error:
mb_obj.set_from_address :from, "[email protected]", {'first' => 'Sending', 'last' => 'User'}
mb_obj.add_recipient :to, "[email protected]", {'first' => 'Recipient', 'last' => 'User'}
mb_obj.set_subject :subject, "This is the subject!"
mb_obj.set_text_body :text, "This is the text body."
That's because set_from_address
should not contain a :from
argument. Same goes for :subject
and :text
, and for the subsequent BatchMessage
lines.
PR to follow.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.