Last active
December 18, 2022 18:34
-
-
Save parterburn/6f2332a815f6616131e6d74254c40012 to your computer and use it in GitHub Desktop.
An example of how to resend messages using the Mailgun API. Per the documentation at https://documentation.mailgun.com/en/latest/api-sending.html#examples. Find your Mailgun Private API Key: https://app.mailgun.com/app/account/security/api_keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mailgun_private_api_key = "key-TKTK" | |
urls = %w[ | |
https://se.api.mailgun.net/v3/domains/{{YOUR_DOMAIN_NAME}}/messages/{{MESSAGE_STORAGE_KEY}}[email protected] | |
https://storage-us-west1.api.mailgun.net/v3/domains/{{YOUR_DOMAIN_NAME}}/messages/{{MESSAGE_STORAGE_KEY}}[email protected] | |
] | |
urls.each do |url| | |
uri = URI.parse(url) | |
params = Hash[URI.decode_www_form(uri.query)] | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request.basic_auth("api", mailgun_private_api_key) | |
request.add_field('Content-Type', 'application/json') | |
request.body = params.to_json | |
response = http.request(request) | |
puts "#{JSON.parse(response.body).dig('message')} // #{url}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment